Log in

View Full Version : How do you iterate through ALL the drop-down menu (select) objects on the form in css



swathi
01-22-2008, 10:45 PM
can any one reply me please urgent

ddadmin
01-22-2008, 11:28 PM
I think you mean using JavaScript (CSS is for styling elements only). In JavaScript, there is the SELECT object, plus the OPTIONS array that together let you access/loop through all options within a SELECT menu. For example:


<form>
<select id="myselect">
<option value="cat">Option 1</option>
<option value="dog">Option 2</option>
<option value="bear">Option 3</option>
</select>
</form>

<script type="text/javascript">
var selectobject=document.getElementById("myselect")
for (var i=0; i<selectobject.length; i++){
alert(selectobject.options[i].text+" "+selectobject.options[i].value)
}

</script>

More info here: http://www.javascriptkit.com/jsref/select.shtml