Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Changing how a function is performed in a form


Message #1 by "Ali Khan" <Empier4552@a...> on Mon, 24 Jun 2002 03:40:16
Hey, heres the problem. Right now I have a script which makes two arrays. 
Each is linked to a radio button. Once one of those radio buttons are 
clicked the array associated is put into a drop down menu using the 
onclick event. I want to change it so instead of using Radio Buttons I can 
use another select menu to select something and then have the associated 
array load into a drop down menu next to it.

Below is the current code.
<script language="JavaScript">
// initalize list of regions
USRegion = new Array(3)
EERegion = new Array(3)
USRegion[0] = "AK"
USRegion[1] = "WA"
USRegion[2] = "ID"
EERegion[0] = "Co. Cork"
EERegion[1] = "Lara"
EERegion[2] = "Essex"

function setRegion(which) {
	var listRegions = document.frmReport.location
	var listLength = listRegions.length
	for (var i = 0; i < listLength; i++) {
		if (which == "US") {
			listRegions.options[i].text = USRegion[i]
		} else {
			listRegions.options[i].text = EERegion[i]
		}
	}
}
</script>

The actual HTML part


<form name="frmReport" method="post" action="invreport-action.cfm">
<input type="Radio" name="region" value="NA" onclick="setRegion
('US')">United States
<input type="Radio" name="region" value="EE" onclick="setRegion
('EE')">European Union
<select name="location">
<option>Co. Cork
<option>Lara
<option>Essex
</select>

I want to change the radio stuff to be like :
<select name="regoin">
<option value="NA" onclick="setRegion('US')">United States
</select>

  Return to Index