Hi guys,
I'm trying to set the default value of a HTML drop-down menu to the value of a PHP variable. The HTML for the menu looks something like this:
I know that to set the default value I would add the "SELECTED" tag in like so:
But how would I set the default value to the value of a variable? For example, if $smoker = 'Yes' then the default value of the drop-down menu would be "Yes".
To achieve the same sort of thing with a text box I have done the following:
But I can't see any easy way to do it with a drop-down menu.
Any suggestions much appreciated.
I'm trying to set the default value of a HTML drop-down menu to the value of a PHP variable. The HTML for the menu looks something like this:
Code:
<select size="1" name="cmbSmoker">
<option>-</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
I know that to set the default value I would add the "SELECTED" tag in like so:
Code:
<option value="Yes" SELECTED>Yes</option>
But how would I set the default value to the value of a variable? For example, if $smoker = 'Yes' then the default value of the drop-down menu would be "Yes".
To achieve the same sort of thing with a text box I have done the following:
Code:
<input type="text" name="txtSmoker" size="5" value=<?php print $smoker ?>>
But I can't see any easy way to do it with a drop-down menu.
Any suggestions much appreciated.