faqts : Computers : Programming : Languages : JavaScript : Forms : Checkboxes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 24 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I count the total no. of checkboxes in a html form?

Jun 9th, 2005 00:11
Russ Locke, Labanya Roy,


// First you need to know that when following the DOM
// checkbox is a type of INPUT tag (tagName)
var ckCnt = 0; // checkbox counter
// tagName is referenced as a CAPITALIZED value
var obj = document.getElementsByTagName('INPUT');
for (i=0; i<obj.length; i++) {
  // type is referenced as a lowercase value
  if (obj[i].type == 'checkbox') {
    ckCnt++;
  }
}
alert(ckCnt);