PDA

View Full Version : reiterating thru form selects and putting each selects (value/text) in its own array?


BrightNail
11-29-2002, 08:58 AM
is there a clever way to reiterate thru a forms select drop downs (generic names that change)..so I would need to reiterate thru these select boxes in order as they appear on the page..

anyways, is there a way to grab each select drop downs values and corresponding text and put them in their own array for each select box..for example..onpage load...having the value/text would be seperated by a ":"

<select name="random name">
<option value="iujyt56trd">someting 1</option>
<option value="sudvb56t">someting 2</option>
</select>

<select name="random name 2">
<option value="iuj66trd">another 1</option>
<option value="a444444">another 2</option>
</select>

the onLoad would create -->

genericArray1 =new Array ("iujyt56trd:someting1", "sudvb56t:something2");

genericArray2 =new Array ("iuj66trd:another 1","a444444:another 2");


and basically, onLoad, the function would cycle thru the selects and each select would have its own array of its value/text pairs..

the reason for this is because the contents of the dropdowns are dynamically created...so when the page loads, I want to 'store' them because there is a reset button...so when they click "reset"..I just run thru the arrays for the appropriate select box and repopulate it...

any ideas?.....actually, my only problem is actually "creating a unique array for each select box and populating it with value/text pairs seperated by a ":"

thansk,
james

chrismiceli
11-29-2002, 06:42 PM
<script type="text/javascript>
randomname = new Array();
randomname0 = new Array();
function willrunonload() {
for (var i = 0; i > 2; i++) {
randomname[i] = document.myForm.randomnname[i].value + ":" + document.myForm.randomname[i].text;
randomname0[i] = document.myForm.randomname0[i].value + ":" + document.myForm.randomname0[i].text;
}
}
</script>
<body onLoad="willrunonload()">
<form name="myForm">
<select name="randomname">
<option value="iujyt56trd">someting 1</option>
<option value="sudvb56t">someting 2</option>
</select>

<select name="randomname0">
<option value="iuj66trd">another 1</option>
<option value="a444444">another 2</option>
</select>
</form>
</body>

this is kind of sloppy, and can be better but i think that is what you want.