Jump to content

[SOLVED] Repopulate Radio Boxes?


thesaleboat

Recommended Posts

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

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/>

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/>

Archived

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

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