nadeemshafi9 Posted June 19, 2008 Share Posted June 19, 2008 hi guys i am trying to get the checkbox.length so i can loop throgh and check if checked but it says the length is |UNDEFINED when i output it in a alert i tried size and it says 0 but there ar three check boxes in my name="zone_type[]" document.getElementById("zone_type[]").length returns undefined plz help thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 19, 2008 Share Posted June 19, 2008 You have set the "names" to be an array, but you are trying to grab that array using getElementById(). And, you can't give multiple elements the same ID anyway. Instead reference the collection by their name as an element of the form: <html> <head> <script type="text/javascript"> function countBoxes() { alert(document.forms[0]['zone_type[]'].length); } </script> </head> <body> <form> Check 1 <input type="checkbox" name="zone_type[]" value="1"><br> Check 2 <input type="checkbox" name="zone_type[]" value="2"><br> Check 3 <input type="checkbox" name="zone_type[]" value="3"><br> <button onclick="countBoxes();">Check</button> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted June 23, 2008 Author Share Posted June 23, 2008 i got it working, set all the same names by creating array of checkboxes [], use getElementSSSSSSSSSSSS Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.