Forum Moderators: coopster

Message Too Old, No Replies

how to repopulate radio buttons

         

ryanoasis

5:23 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



I am using php, I am passing form elements through the http header and the query string, but I am confused as how to do the same thing with the radio.

1st page: user enters info

2nd page: error checks, if incorrect: send back to page 1 and repopulate all form elements. I do not know how to repopulate the radio buttons.

You should be able to pass it as a variable...

page 1:

<input type="radio" name="optRadio" checked="<?=strChecked?>"> Last Name:

page 2:

if($optRadio == "lastName") {
nameValidate();
$strChecked = "checked";
}

This works but how would I set this up for multiple radio buttons. Or is there an easier way all together to do this?

thanks

felix

6:16 pm on Feb 10, 2003 (gmt 0)

10+ Year Member



If I understand your question correctly, your php code might look something like this

...
if ($position=="top") $radio1["top"]=" checked";
else radio1["top"]="";
if ($position=="middle") $radio1["middle"]=" checked";
else radio1["middle"]="";
if ($position=="bottom") $radio1["bottom"]=" checked";
else radio1["bottom"]="";
...
<input type="radio" name="position" value="top" <? echo $radio1["top"];?>>Top<br>
<input type="radio" name="position" value="middle" <? echo $radio1["middle"];?>>Middle<br>
<input type="radio" name="position" value="bottom" <? echo $radio1["bottom"];?>>Bottom<br>
...