...

View Full Version : get element by id?



nikko50
04-24-2008, 04:30 AM
How do I get the options length of my select list by id. I tried the below but get an error stating "example1 not defined.




<form name="doublecombo">
<p>
<select name="example1" id="example1" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Technology Sites</option>
<option>News Sites</option>
<option>Search Engines</option>
</select>
</form>


<script>
<!--

var groups=document.getElementById(example1).options.length

</script>

Arty Effem
04-24-2008, 04:40 AM
How do I get the options length of my select list by id. I tried the below but get an error stating "example1 not defined.


var groups=document.getElementById(example1).options.length


IDs are strings and must be specified as such:

var groups=document.getElementById("example1").options.length



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum