...

View Full Version : Checkbox check all



treeleaf20
12-03-2009, 02:47 PM
All,
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)\">";
[PHP]

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:
[PHP]
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?

Thanks!

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


onClick=\"checkAll(document.photos.elements['picbigid[]'])\"

Look at my sig for more info of this technique.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum