My problem probally is a common one, I'm sure someone's experience will help me out here!
I am using check boxes in a form to return an array of values to a php script. I need to have a check all checkbox that checks every other checkbox. Seems like i need to use javascript to do this.
My problem comes up when i need to place the [] in the field name (for php to recognize an array). The javascript works when i ommit the [], but then php keeps overwriting the field insted of seeing it as an array.
I call this function like this: area_checkbox($db,"area[]"
function area_checkbox($connect,$cname){
$foo=list_areas($connect);
echo "<SCRIPT LANGUAGE='JavaScript'>
function dochange(){
foo = document.asearch.elements['$cname'];
box=ducument.asearch.abox;
if(box.checked==true)
checkAll(foo);
else
uncheckAll(foo);
}
function checkAll(foo){
for (i = 0; i < foo.length; i++){
foo.checked = true ;
}
}
function uncheckAll(foo){
for (i = 0; i < foo.length; i++){
foo.checked = false ;
}
}
</script>";
print("<table border=1 cellpadding=5>"
for($cntr=0;$cntr<count($foo);$cntr++){
if(($cntr+1)%3==1)
echo "<tr>";
list($code,$name)=$foo[$cntr];
print("<td width=120><input type='checkbox' value='$code' name='$cname'>$name</td>"
if(($cntr+1)%3==0)
echo "</tr>";
}
if((count($foo)+1)%3<>0)
echo "</tr>";
echo "<tr><td width=120 colspan=3><input type='checkbox' name='abox' onClick='dochange();'>Check All</td></tr></table>";
}
Any Ideas?
I am using check boxes in a form to return an array of values to a php script. I need to have a check all checkbox that checks every other checkbox. Seems like i need to use javascript to do this.
My problem comes up when i need to place the [] in the field name (for php to recognize an array). The javascript works when i ommit the [], but then php keeps overwriting the field insted of seeing it as an array.
I call this function like this: area_checkbox($db,"area[]"
function area_checkbox($connect,$cname){
$foo=list_areas($connect);
echo "<SCRIPT LANGUAGE='JavaScript'>
function dochange(){
foo = document.asearch.elements['$cname'];
box=ducument.asearch.abox;
if(box.checked==true)
checkAll(foo);
else
uncheckAll(foo);
}
function checkAll(foo){
for (i = 0; i < foo.length; i++){
foo.checked = true ;
}
}
function uncheckAll(foo){
for (i = 0; i < foo.length; i++){
foo.checked = false ;
}
}
</script>";
print("<table border=1 cellpadding=5>"
for($cntr=0;$cntr<count($foo);$cntr++){
if(($cntr+1)%3==1)
echo "<tr>";
list($code,$name)=$foo[$cntr];
print("<td width=120><input type='checkbox' value='$code' name='$cname'>$name</td>"
if(($cntr+1)%3==0)
echo "</tr>";
}
if((count($foo)+1)%3<>0)
echo "</tr>";
echo "<tr><td width=120 colspan=3><input type='checkbox' name='abox' onClick='dochange();'>Check All</td></tr></table>";
}
Any Ideas?