rockinaway Posted March 10, 2007 Share Posted March 10, 2007 What I wish to do is have a radio button pre-selected depending on what is pulled from the database. For example if I had 2 radio buttons: o Yes o No One has the value 1 and the other has the value 0 If 1 is selected from the database then Yes is pre-selected, else 0 is pre-selected. How would I do this? Link to comment https://forums.phpfreaks.com/topic/42142-radio-button-selected/ Share on other sites More sharing options...
Orio Posted March 10, 2007 Share Posted March 10, 2007 <?php //$select holds 1 or 0 as taken for the db echo "<input type=\"radio\" value=\"yes\""; if($select == 1) echo " checked=\"checked\""; echo ">Yes"; echo "<input type=\"radio\" value=\"no\""; if($select == 0) echo " checked=\"checked\""; echo ">No"; ?> Haven't tested it, but it should work. Orio. Link to comment https://forums.phpfreaks.com/topic/42142-radio-button-selected/#findComment-204411 Share on other sites More sharing options...
rockinaway Posted March 10, 2007 Author Share Posted March 10, 2007 Right another problem. I have several values in an array for which I have radio buttons. What is the quick way to do that for all values .. Link to comment https://forums.phpfreaks.com/topic/42142-radio-button-selected/#findComment-204437 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 foreach loop is your best bet. --FrosT Link to comment https://forums.phpfreaks.com/topic/42142-radio-button-selected/#findComment-204440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.