[Javascript] select all checkboxes script

Michael Borchers list at tridemail.de
Tue Feb 7 09:54:34 CST 2006


combining with php by giving the amount of rows 0-...
would have been a solution too:
http://www.php-resource.de/forum/showthread/t-59586.html

but i solved it this way:
function checkBox(formName, thisCheckbox, checkboxSubstring)
{
 if(thisCheckbox.checked == true)
 {
  var checked = true;
 }
 else
 {
  var checked = false;
 }

 checkboxField = document.forms[formName].getElementsByTagName("input");

    for(c=0;c<checkboxField.length;c++)
 {
        if(checkboxField[c].getAttribute("name").substring(0, 
checkboxSubstring.length) == checkboxSubstring)
  {

   checkboxField[c].checked = checked;
  }
    }
}

and the input button:
<input type="checkbox" name="checkBoxSelect" id="checkBoxSelect" 
onclick="javascript:checkBox('time_sheets', this, 'time_sheets');" />

the checkbox f.e.:
<input type="checkbox" name="time_sheets[9][time_sheets_id]" 
id="time_sheets[9][time_sheets_id]" value="1391">


what do you think? 




More information about the Javascript mailing list