View Full Version : Checkbox check all

12-03-2009, 03:47 PM
I have the following checkbox code:

echo "<input name=\"picbigid[]\" type=\"checkbox\" value=\"$pic[src_big]\">";

I then want to select all the checkboxes so I have this code:

echo "<input type=\"button\" name=\"CheckAll\" value=\"Check All\" onClick=\"checkAll(document.photos.picbigid)\">&nbsp;&nbsp;<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\" onClick=\"uncheckAll(document.photos.picbigid)\">";

My JS function is:

function checkAll(field)
for (i = 0; i < field.length; i++)
field[i].checked = true ;
function uncheckAll(field)
for (i = 0; i < field.length; i++)
field[i].checked = false ;

If I do it like this:
echo "<input name=\"picbigid\" type=\"checkbox\" value=\"$pic[src_big]\">";

It works but I can't have it like that because the form posts to another PHP page that needs the input name as an array.

Any ideas?


12-03-2009, 11:29 PM
You need to use the square bracket notation.


Look at my sig for more info of this technique.