Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    get element by id?

    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.



    Code:
    <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>

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by nikko50 View Post
    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.
    Code:
    var groups=document.getElementById(example1).options.length
    IDs are strings and must be specified as such:
    Code:
    var groups=document.getElementById("example1").options.length


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •