Jump to content

Radio button selected


rockinaway

Recommended Posts

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

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

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.