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

checkboxes

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

Just like in a regular inbox of an email, how can we check without using a switch, the checkboxes that has been checked, or how can we do a Select All, that will check all checkboxes, without manually typing the names of the checkboxes (checkbox1,checkbox2, etc.)

Thanks

miketb69

 
You can loop thru the form's elements array, and ask each element it's type - if it returns "checkbox", then you can check it by saying - checkboxName.checked=true:



function checkAll(){

var form = document.forms['formName'];

for(var j=0; j<form.elements.length; j++){

if(form.elements[j].type == &quot;checkbox&quot;){
form.elements[j].checked = true;
}
else{/* not a checkbox */}
}

}


To see which has been checked - do a similar thing - loop thru the checkboxes querying the 'checked' property of the checkboxes.
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top