Thursday, 12 September 2013

how can i make a default value if the option value of a select tag isnt a specific value?

how can i make a default value if the option value of a select tag isnt a
specific value?

<select name="corequisite">
<option value="" selected="selected">No Corequisite</option>';
$res = mysql_query("SELECT * FROM course");
while($row = mysql_fetch_array($res)){
echo'<option
value="'.$row['Code'].'"';if($row['Code']==$result['corequisite'])
echo'
selected="selected"';;echo'>'.$row['Name'].'</option>';
}
echo'</select>';
I want the 'No Corequisite' value to be selected if no other options will
be match with $result['corequisite']. But the first item in the table will
be selected!
How can I fix it?
It may be fixed by inserting 'corequisite' as the first record. A good way?

No comments:

Post a Comment