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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.