Jump to content

select correct item from dropdown list


centenial

Recommended Posts

Hi,

I have a dropdown list similiar to this:

[code]<select name="dropdown">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>[/code]

Now, in my database table I have a field called 'dropdown' and in it is one of those values (Let's say "3" for an example). Now, on my edit page I want to display that dropdown (select) list but have the correct item selected. Like this (For example):

[code]<select name="dropdown">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>[/code]

Now if I change it to "2", "5", or any other option next time I go to the edit page the correct item should be selected. How should I go about doing this? Is there an easy function that accomplishes it?

Thanks!
Link to comment
Share on other sites

The easiest way is to add the value as the first options like this (if three is selected)
[code]
<select name="dropdown">
<option value="3">3</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
[/code]
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.