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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check all check boxes on the form

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
How to check all check boxes on the form without referring to their names and not knowing how many of them are present on the form?

Thanks.
 
Well, if all the checkboxes are in the same form and, for example, that is document.forms[0] on your page, you can program a button's onclick event to call checkAll() which would be something like this:

Code:
function checkAll()
{
 for(var i=0; i<document.forms[0].elements.length; i++)
  if(document.forms[0].elements[i].type == 'checkbox')
   document.forms[0].elements[i].checked = true;
}

This worked for me in IE6.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top