I found a nice example of a javascript that allows you to check or uncheck all of the checkboxes in a form. I've hit a roadblock in my implementation because I need each checkbox to have a different name or be part of an array (preferably the former).
I've tried putting the checkbox name in [] like this:
But that does not work for me.
Any assistance would be appreciated.
Here is the full test code that I'm using:
I've tried putting the checkbox name in [] like this:
Code:
<input type="button" name="Check_All" value="Check All" onClick="Check(document.testform.["check_box[]"])">
Any assistance would be appreciated.
Here is the full test code that I'm using:
Code:
<?
echo "<SCRIPT LANGUAGE=\"JavaScript\">";
echo "function Check(chk)";
echo "{";
echo "if(document.testform.Check_All.value==\"Check All\"){";
echo "for (i = 0; i < chk.length; i++)";
echo "chk[i].checked = true ;";
echo "document.testform.Check_All.value=\"UnCheck All\";";
echo "}else{";
echo "for (i = 0; i < chk.length; i++)";
echo "chk[i].checked = false ;";
echo "document.testform.Check_All.value=\"Check All\";";
echo "}";
echo "}";
echo "</script>";
echo "<form name='testform' action='' method='post'>";
echo "<input type='checkbox' name='check_box[]' value='1'>1<br>";
echo "<input type='checkbox' name='check_box[]' value='2'>2<br>";
echo "<input type='checkbox' name='check_box[]' value='3'>3<br>";
echo "<input type='checkbox' name='check_box[]' value='4'>4<br>";
echo "<input type='checkbox' name='check_box[]' value='5'>5<br>";
echo "<input type='button' name='Check_All' value='Check All' onClick='Check(document.testform.['check_box[]'])'>";
echo "</form>";