Jazzy 1012
asked on
Put radio button in my form but already has components from my database
<tr>
<td>Gender</td>
<td><span id= "keep2"><?php echo $gender; ?></span><input id= "change2" value= "<?php echo $gender; ?>" style= "display:none;" name="gen"></td>
</tr>
I have these variables connected to my database, as you can see it displays the gender, and when I click edit it becomes an input value that I can change, However how can I make it that when I click on edit, for $gender instead of showing "female" for example it will show male or female radio button with the button on the gender that is shown in the database, for example for female the button will be on female.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Correction to above code - left out name attribute of second radio
<tr>
<td>Gender</td>
<td>
<span id= "keep2"><?php echo $gender; ?></span>
<input id= "change2a" type="radio" value= "male" checked="<?php echo $gender == 'male' ? 'checked': ''; ?>" style= "display:none;" name="gen"/>
<input id= "change2b" type="radio" value= "female" checked="<?php echo $gender == 'female' ? 'checked': ''; ?>" style= "display:none;" name="gen"/>
</td>
</tr>
ASKER
Yeah I saw that and switched it, thank you
When db has male
<input type=radio name=gender checked value=male>
<input type=radio name=gender value=Female>
When db has female
<input type=radio name=gender value=male>
<input type=radio name=gender checked value=male>
Ref
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio
When you hit edit, your php code needs to output the form with the db item set as checked....