0

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>";
3
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

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>";
0

Sample

<select name="select">
<?php 
if($row[0]=='India')$dtext = "selected";
  else $dtext = "";
print("<option $dtext value=\"$row[0]\">$row[0]</option>");
?>
</select>

Edited by rajarajan07: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.