Deserteye Posted October 18, 2006 Share Posted October 18, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/24281-how-to-echo-a-checkbox-and-radio-button-if-checked-or-not/ Share on other sites More sharing options...
chriscloyd Posted October 18, 2006 Share Posted October 18, 2006 well did u save them into a database when they choose if they want to or not? Quote Link to comment https://forums.phpfreaks.com/topic/24281-how-to-echo-a-checkbox-and-radio-button-if-checked-or-not/#findComment-110491 Share on other sites More sharing options...
manichean Posted October 18, 2006 Share Posted October 18, 2006 All you have to do is get the value (presumably you storing it in a databse) and perform the followingFor 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 falseif ($row['checkbox']){ $checkboxChecked = "checked=\"checked\"";}else{ $checkboxChecked = "";}?><input type="checkbox" name="checkbox" value="checkbox" id="checkbox" <?php echo $checkboxChecked ?> />[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/24281-how-to-echo-a-checkbox-and-radio-button-if-checked-or-not/#findComment-110492 Share on other sites More sharing options...
Daniel0 Posted October 18, 2006 Share Posted October 18, 2006 Shorter: [code]<input type="checkbox" name="checkbox" value="checkbox" id="checkbox"<?php echo $row['checkbox'] ? ' checked="checked"' : null; ?> />[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24281-how-to-echo-a-checkbox-and-radio-button-if-checked-or-not/#findComment-110509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.