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?
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.