Jump to content

Archived

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

Deserteye

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

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Shorter: [code]<input type="checkbox" name="checkbox" value="checkbox" id="checkbox"<?php echo $row['checkbox'] ? ' checked="checked"' : null; ?> />[/code]

Share this post


Link to post
Share on other sites

×

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.