www.webdeveloper.com
Results 1 to 4 of 4

Thread: count number of select lists with same name?

  1. #1
    Join Date
    Jan 2005
    Location
    UK
    Posts
    381

    count number of select lists with same name?

    Hi,

    Can anyone tell me how I can do this? I need to vaidate them before the form is sent.

    I can get the html collection object by using:

    var w00t = document.getElementById('equipmentlist'+i).getElementsByTagName('select');
    alert(w00t.length);

    Can anyone tell me how I can get the number of instances? If i use the length property it just gives me the number of options in the list.


    Thankyou
    Last edited by mattastic; 01-25-2007 at 07:16 AM.

  2. #2
    Join Date
    Nov 2006
    Posts
    137
    just try

    Code:
    var w00t = document.getElementsByTagName('select');
    alert(w00t.length);

  3. #3
    Join Date
    Aug 2006
    Location
    Turkey
    Posts
    242
    alert(w00t[0].options.length);
    Code:
      
    
    <script type="text/javascript">
    
    window.onload = function () {
    
    var w00t = document.getElementById('mydiv').getElementsByTagName('select');
    
    alert(w00t[0].options.length);  // 5
    alert(w00t[1].length);   // 2
    }
    
    </script>
    
    
    <div id="mydiv">
    <select>
    <option>ee</option>
    <option>ee</option>
    <option>ee</option>
    <option>ee</option>
    <option>ee</option>
    
    </select>
    
    <select>
    <option>ee</option>
    <option>ee</option>
    </select>
    </div>

  4. #4
    Join Date
    Jan 2005
    Location
    UK
    Posts
    381
    THanks for your replies.

    I still having real problems with this. Can anyone help?

    I have uploaded my page here:

    http://www.halesowen.ac.uk/javascript_test.cfm

    All I want to do is validate the fields users enter and make sure nothing is left blank.

    My main problem is adding equipment, if you click the 'add' button, you can add pieces of equipment and there quanity, I just need to make sure users dont add a piece if equipment and leave the 'please select' as selected.

    I cant get javascript to access the select lists of the same name, i could then loop through them and check the selectedindex isnt set to 0.

    Can anyone please help?

    Thankyou
    Last edited by mattastic; 01-25-2007 at 12:00 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles