PDA

View Full Version : Changing the value of a drop down



mbriney
03-30-2007, 09:09 PM
I have a strange request for help.

I have a form that has three identical select boxes. All of the select option tags are exactly the same and in the same order. Each select box has a unique ID number.

What I was wondering is if it would be possible to do an onchange event that if someone selects a value in one of the drop downs it automatically changes it on the other two drop downs.

I'm not even sure where to begin here.

Thanks,
-Matt

Twey
03-30-2007, 10:03 PM
Simple enough...
<form action="" name="formname">
<select name="select0">
<!-- ... options ... -->
</select>
<select name="select1">
<!-- ... options ... -->
</select>
<select name="select2">
<!-- ... options ... -->
</select>
<!-- ... more ... -->
</form>
<script type="text/javascript">
var changeHandler = function() {
for(var i = 0, e = document.forms['formname'].elements; s = e['select' + i]; ++i)
s.selectedIndex = this.selectedIndex;
};
for(var i = 0, e = document.forms['formname'].elements; s = e['select' + i]; ++i)
s.onchange = changeHandler;
</script>