Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting the number of checkboxes

Status
Not open for further replies.

ingernet

Programmer
Feb 5, 2001
68
US
Hi there, I need to get the number of checkboxes in a given form. Would I use something like this line below?

Code:
document.myFormName.element.checkbox.length

...Or is there another way to do this without looping throughout all the elements and counting them one at a time, manually?

Thanks!
Inger
 
Something like that. The following would be the number of elements in the form. The elements property is an array.
Code:
document.myFormName.elements.length

You must loop through that array and test the type of each element. Count the ones with a type of checkbox.
Code:
var nCkboxes = 0;
for(var i=0; i < document.myFormName.elements.length ; i++){
  if( document.myFormName.elements[i].type == "checkbox" ) {
    nCkboxes++;
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top