Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an update query, which is working fine. When I click on the edit button, it shows the field with content inside it, which we want to edit or update.

It is working fine with <input type="text" /> but I also want it with <select> tag.

code is like this
<select name='location' value="<?php echo $row['location']; ?>">
                 <option value=''> - Select - </option>
                 <option value='Anywhere' >Anywhere</option>
                 <option value='Ahmedabad' >Ahmedabad</option>
                 <option value='Bangalore' >Bangalore</option>
                 <option value='Chennai' >Chennai</option>
                 <option value='Delhi' >Delhi</option>
                 <option value='Delhi Region' >Delhi Region</option>
                 <option value='Gurgaon' >Gurgaon</option>
                 <option value='Hyderabad' >Hyderabad</option>
                 <option value='Kolkata' >Kolkata</option>
                 <option value='Mumbai' >Mumbai</option></select>

So i want whatever i city already chose, it should show on edit page, but in my case its not showing, i have to select again, if i am not selecting any city then it shows blank in the database.

Can anyone help me in this, what i do or what i have to change
Posted
Updated 10-Jan-12 0:35am
v2
Comments
Slacker007 10-Jan-12 6:36am    
Edits made: Some formatting and readability.

1 solution

You would need to set the selected property of the option that should be selected. So, if Anywhere should be selected, the result would be:
<option value="Anywhere" selected="selected">Anywhere</option>

Best would be to add the options using a loop and add the selected property to the selected option.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900