Dynamic checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

Dynamic checkbox

Post 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\" >");
?>
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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?
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

when checkbox is checked submited value is 'on'
else submited value is not set (don't have $_POST['checkboxname'] )
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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. :)
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

Them darn checkboxes

Post 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.
Post Reply