Jump to content

how to echo a checkbox and radio button (if checked or not)


Deserteye

Recommended Posts

I have a script where a user has options to choose if he/she wants to recieve emails from other members. but I want the user to be able to edit that. When they go into their user cp, how would I echo either if the checkbox is checked or not by what it is currently set to?
All you have to do is get the value (presumably you storing it in a databse) and perform the following

For a checkbox (you do the same for a radio button)
[quote]
<?php
// This assumes you have pulled the info from a database storing it into $row['checkbox']
// and that you know the value to either be true or false
if ($row['checkbox']){
$checkboxChecked = "checked=\"checked\"";
}else{
$checkboxChecked = "";
}
?>
<input type="checkbox" name="checkbox" value="checkbox" id="checkbox" <?php echo $checkboxChecked ?> />
[/quote]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.