runnerjp Posted February 19, 2009 Share Posted February 19, 2009 <select id="gender" name="gender"> <option value="Male" selected="<?php echo $getuserprofile['gender']; ?>" >Male</option> <option value="Female" selected="<?php echo $getuserprofile['gender']; ?>" >Female</option> </select> when i use <?php echo $getuserprofile['gender']; ?> on its own it shows male as this is in the db... but when i use it like the code above it shows female :S Link to comment https://forums.phpfreaks.com/topic/145915-solved-menu-not-echoing-out-selected/ Share on other sites More sharing options...
phpdragon Posted February 19, 2009 Share Posted February 19, 2009 Hi you misunderstand the html use of the selected option it is used as follows <select name='gender' id='gender'> <option value='Male' selected>Male</option> <option value='Female'>Female</option> </select> notice how it is only the word selected and not selected='xxx' what you must do is an if statement to echo selected into the tag when your value is true $true=$getuserprofile['gender']; <select name='gender' id='gender'> <option value='Male' <?php if ($true=='Male') {echo "selected";} ?>>Male</option> <option value='Female'<?php if ($true=='Female') {echo "selected";} ?>>Female</option> </select> Link to comment https://forums.phpfreaks.com/topic/145915-solved-menu-not-echoing-out-selected/#findComment-766067 Share on other sites More sharing options...
runnerjp Posted February 19, 2009 Author Share Posted February 19, 2009 ahh thanks alot... good explanation to set me on right track Link to comment https://forums.phpfreaks.com/topic/145915-solved-menu-not-echoing-out-selected/#findComment-766072 Share on other sites More sharing options...
phpdragon Posted February 19, 2009 Share Posted February 19, 2009 I am glad you understood as re reading it I noticed I neglected to mention that my first example would show male as the selected option Link to comment https://forums.phpfreaks.com/topic/145915-solved-menu-not-echoing-out-selected/#findComment-766082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.