Click to See Complete Forum and Search --> : working with radio buttons


btkaruna
November 29th, 2004, 04:10 AM
i have a radio button for gender storing m or f into msql database.how can i assigned value back to the radio button on php form based on m or f stored in mysql

thanks a lot

visualAd
November 30th, 2004, 05:37 PM
<input type="hidden" name="gender" value="undefined" />
Male: <input type="radio" name="gender" value="m" /><br />
Female: <input type="radio" name="gender" value="f" />


The values m or f will be passed back to your script. If the user fails to select one, then the value undefined is sent.

Little tip: don't set a default as it could be seen as sexist. ;)
But if you did want one checked by default just add the checked="checked" attribute to the input tag.

Nytro08
December 12th, 2004, 07:25 PM
echo("Male: <input type='radio' name='gender' value='m'")
if($gender == m) {
echo(" checked>");
} else {
echo(">");
}
echo("Female: <input type='radio' name='gender' value='f'")
if($gender == f) {
echo(" checked>");
} else {
echo(">");
}