fragmaster Posted March 9, 2008 Share Posted March 9, 2008 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. Quote Link to comment Share on other sites More sharing options...
haku Posted March 9, 2008 Share Posted March 9, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.