SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: how many checkboxes?
-
Mar 29, 2007, 02:05 #1
how many checkboxes?
I have 2 checkboxes with the same name and different values. I have a validation script which checks various form entries (it can be used on any form). I am trying to check that at least one of the values has been checked.
Code:if(type=='tf'){ var oneChecked=false for(i=0;i<document.getElementById(objName).length;i++){ if(document.getElementById(objName)[i].checked==true){ oneChecked=true break; } } if(oneChecked==false){ errors=errors+label+' must be selected\n'; return; } }
What is going wrong?
cheers
monkeymonkey - the rest is history
-
Mar 29, 2007, 02:16 #2
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can iterate through the checkboxes with the same name using getElementsByName. You are now using getElementById, which will get a specific node matching that id. Ids are unique, so you shouldn't have more than one element with the same id.
-
Mar 29, 2007, 03:54 #3
Bookmarks