Page 1 of 1
Dynamic checkbox
Posted: Fri Nov 29, 2002 9:56 am
by Deddog
Is there a way that the below code can be amended so that if the checkbox is not checked then the varibale gains a value of 0?
<?PHP
printf("<input type=\"checkbox\" name=\"EasyList\" value=\"1\" >");
?>
Posted: Fri Nov 29, 2002 10:25 am
by Jim
That happens pretty much automatically, as far as I understand it.
Maybe you should only check for values of 1 in your processing code?
Posted: Fri Nov 29, 2002 10:32 am
by PaTTeR
when checkbox is checked submited value is 'on'
else submited value is not set (don't have $_POST['checkboxname'] )
Posted: Fri Nov 29, 2002 10:50 am
by Jim
Well, I guess you could do this:
if(!$_POST['variable_name']) {
$variable_name = '0';
}
Basically, if variable_name isn't selected, set it to 0.
You'd have to change those variable_names out to the name of the variables you're using... but it should work.

Them darn checkboxes
Posted: Fri Nov 29, 2002 11:01 am
by Deddog
Thanks for the replies lads.
I'd already gone for Jim's idea, but it would have been nice to tie it up when i defined the checkbox.
Cheers,
Lee.