Crash Landing
Crash Landing

Reputation: 23

Select not starting at the specified option value

I am attempting to create an empty option that starts as "selected" so that I can run a check to make sure an option was chosen from the drop down menu. However, for some reason the option I marked as selected doesn't start off selected from the drop down. Anybody have an idea as to why?

<select name="PCP" id="PCP">
  <option value="" selected="selected"></option>
    <?php 
$sql_status = "SELECT * FROM providers WHERE PCP = 'Y'";

$rs_status = mysql_query($sql_status);
while($row_status = mysql_fetch_array($rs_status))
{
echo "<option value=\"".$row_status['PROVID']."\">".$row_status['FULLNAME']."\n  ";
}
?>
</select>

Upvotes: 0

Views: 86

Answers (1)

vee
vee

Reputation: 38645

Don't you want to close your <option> with </option> like following?

echo "<option value=\"".$row_status['PROVID']."\">".$row_status['FULLNAME']."</option>";

Update:

Since PHP will evaluate variables within double quotes, you could simplify the above statement as follows:

echo "<option value='$row_status['PROVID']'>$row_status['FULLNAME']</option>";

Upvotes: 4

Related Questions