hey guys, i have this code in php i don't know if this works but there is no error at all. i am trying to get the value from a database and assign it as the value of the combo box.

echo "<td align=left><font size = '2'><select name='status' id='status' selecteditem='$status'><option>Active</option><option>Resigned</option></select>";

Recommended Answers

All 2 Replies

If you want a specific option to be the selected one, you must add selected="selected" to the option tag, not the select tag. You code would look something like this:

$activeSelected = ($status == 'Active') ? "select='selected'" : '';
$resignedSelected = ($status == 'Resigned') ? "select='selected'" : '';
echo "<td align=left><font size='2'><select name='status' id='status'><option $activeSelected>Active</option><option $resignedSelected>Resigned</option></select>";
Member Avatar


<select name="select">
if($row[0]=='India')$dtext = "selected";
  else $dtext = "";
print("<option $dtext value=\"$row[0]\">$row[0]</option>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.