Jump to content

Value of a combobox based upon a php value


fragmaster

Recommended Posts

Hi,

 

Im having a problem with a combo box. I am retreiving a value from a MySQL database that coresponds to a value in the combo box. Probably best if i show the code and people might understand what im on about...

 

<td>Location:<br>

<select name="location" id="location" value="<?PHP PRINT("$location"); ?>">

<option value="null">(Please Select)</option>

<option value="L001">Kitchen</option>

<option value="L002">Attendance Office</option>

<option value="L003">Personal Office</option>

<option value="L004">Reception</option>

<option value="L005">Main Office</option>

 

Lets say that $location = L004, when the page loads i want the combobox to display "Reception" instead of "(Please Select)".

 

This method seems to work when populating the value of a text field but im having no luck with combo boxes.

 

 

Any help would be greatly appreciated.

You want to echo:

 

selected="selected"

 

into the option tag that you want to appear. You will have to use an if statement to check whether or not the tag should have this text added.

 

Note: if you add it to more than one option tag, it will show the last one.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.