Forum Moderators: coopster
Lager Wine Beer Spirits
<input type="radio" name="category" value="Beer" CHECKED>Beer
<input type="radio" name="category" value="Lager">Lager
<input type="radio" name="category" value="Wine">Wine
<input type="radio" name="category" value="Spirits">Spirits
If I want the user to update this via another page and form, how do I set the default value? I can read in the value from the database, say WINE, but how do I set WINE as the default value for the user to modify, if required?
Do I set some IF statements?
if ($category == "Beer") {
<input type="radio" name="ud_category" value="Beer" CHECKED>Beer
} Else {
<input type="radio" name="ud_category" value="Beer">Beer
} ....etc....etc
Or is there a quick method?
Look forward to some answers.
Andy
$selections = array("Wine","Beer","Lager","Spirits"); //build array
for($i = 0; $i < count($selections); $i++) //start looping
{
if ($_POST["category"] == $selections[$i])
{
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\" CHECKED>".$selections[$i]."   />;
} else {
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\">".$selections[$i]."   />;
}
}
<some code removed, but nothing that affects the form>
$category=mysql_result($result,$i,"category");
$priority=mysql_result($result,$i,"priority");
?>
<form onSubmit="name="frm" action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo "$id";?>">
$selections = array("Wine","Beer","Lager","Spirits"); //build array
for($i = 0; $i < count($selections); $i++) //start looping
{
if ($_POST["category"] == $selections[$i])
{
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\" CHECKED>".$selections[$i]."   />;
} else {
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\">".$selections[$i]."   />;
}
}
<br>
Priority: <input type="text" name="ud_priority" value="<? echo "$priority"?>"><br>
<input type="Submit">
<input type="reset" value="Reset!"><br>
</form>
Andy.
Try inserting this instead:
<form onSubmit="name="frm" action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id;?>">
$selections = array("Wine","Beer","Lager","Spirits"); //build array
for($i = 0; $i < count($selections); $i++) //start looping {
if ($_POST["category"] == $selections[$i]) {
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\" CHECKED>".$selections[$i]."   />";
} else {
print "<input type=\"radio\" value="".$selections[$i]."" name=\"ud_category\">".$selections[$i]."   />";
}
}
<br>
Priority: <input type="text" name="ud_priority" value="<? echo $priority?>"><br>
<input type="Submit">
<input type="reset" value="Reset!"><br>
</form>
if ($category == $selections[$i]) {
print "<input type='radio' value='".$selections[$i]."' name='ud_category' CHECKED>".$selections[$i]."   ";
} else {
print "<input type='radio' value='".$selections[$i]."' name='ud_category'>".$selections[$i]."   ";
}
Once again, thanks for your help. This is a great forum for us novices. I'm please to see that help is given without making us look stupid when we ask the simple questions. Keep up the excellent work.
print "<input type=\"radio\" value="".$selections[$i].""
it should read:
print "<input type=\"radio\" value=\"".$selections[$i]."\"
I never escaped the quotes for the value attribute.