0

I have a simple 2 option drop down menu which corresponds to a column in my database.
The drop down menu is not populated by the database it is just used to update the data in that 1 column. However I was wondering if it would be possible to make the selected option in the dropdown menu mirror the value currently held in the database.

<select name="attend">
  <option value="No">No</option>
  <option value="Yes">Yes</option>
</select>

So I would like to make Yes be the selected option if the field it will corresdond to in the database is yes.I know I will need to do a select query but apart from that I'm alittle clueless.

Hope someone can help.

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by Mecklar
0

The option to be selected needs the word 'selected' after the value=xxx. In order to make this dynamic, you need a variable as part of each option as follows:

<select name="attend">
  <option value="No"<?PHP echo $selected_no; ?> >No</option>
  <option value="Yes" <?PHP echo $selected_yes; ?> >Yes</option>
</select>

Before you get to this point, you will decide if it is to be yes or no and set one variable to empty and the other one to 'selected'.

0

Just added in the if statement etc. Took me alittle bit of messing around with the code since it's between a <<<EOD but it now works.

Thanks Chrishea, your explanation really helped.

This question has already been answered. 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.