thesaleboat Posted May 14, 2009 Share Posted May 14, 2009 Ok, I just was showed how to make the text boxes repoplulate and allow for later updating by the user... <input type="text" name="address" id="address" value="<?php echo isset($_POST['address']) ? $_POST['address'] : $rows['address'];?>" size="50" maxlength="50" /> now i was wondering if there is a similar way to repopulate the radio boxes, all i have right now is a simple html code for them... <input type="radio" name="gender" value="Male" checked="checked"/>Male<br/> <input type="radio" name="gender" value="Female"/>Female<br/> And they go back to default after submission, help plz? Link to comment https://forums.phpfreaks.com/topic/158151-solved-repopulate-radio-boxes/ Share on other sites More sharing options...
Brian W Posted May 14, 2009 Share Posted May 14, 2009 you need a conditional statement to determin whether to print "checked=\"checked\"" or not. The condition will likely be something like <?php if($_POST['gender'] == "Male" || $rows['gender'] == "Male"){ echo "checked=\"checked\""; } ?> Link to comment https://forums.phpfreaks.com/topic/158151-solved-repopulate-radio-boxes/#findComment-834223 Share on other sites More sharing options...
thesaleboat Posted May 15, 2009 Author Share Posted May 15, 2009 Ok, this is what I have now, it doesn't quite work (it shows up on the page as checked but in the database it doesn't insert a value)... hmm <input type="radio" name="gender" value="<?php if($_POST['gender'] == "Male" || $rows['gender'] == "Male"){ $checked=1; } ?>" checked="<?php if($checked=1) "checked" ?>"/>Male<br/> <input type="radio" name="gender" value="<?php if($_POST['gender'] == "Female" || $rows['gender'] == "Female"){ $checked=1; } ?>" checked="<?php if($checked=1) "checked" ?>"/>Female<br/> Link to comment https://forums.phpfreaks.com/topic/158151-solved-repopulate-radio-boxes/#findComment-834805 Share on other sites More sharing options...
thesaleboat Posted May 15, 2009 Author Share Posted May 15, 2009 Got it, had to take out the code later on in the page //$gender=$_POST['gender']; This is what ended up working, if anyone wanted to know... <input type="radio" name="gender" value="<?php if($_POST['gender'] == "Male" || $rows['gender'] == "Male"){ $gender = "Male"; } ?>" checked="<?php if($gender = "Male") "checked" ?>"/>Male<br/> <input type="radio" name="gender" value="<?php if($_POST['gender'] == "Female" || $rows['gender'] == "Female"){ $gender = "Female"; } ?>" checked="<?php if($gender = "Female") "checked" ?>"/>Female<br/> Link to comment https://forums.phpfreaks.com/topic/158151-solved-repopulate-radio-boxes/#findComment-834819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.