Jump to content


Photo

select correct item from dropdown list


  • Please log in to reply
1 reply to this topic

#1 centenial

centenial
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 26 May 2006 - 11:37 PM

Hi,

I have a dropdown list similiar to this:

<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>

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):

<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>

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!

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 27 May 2006 - 12:37 AM

The easiest way is to add the value as the first options like this (if three is selected)
<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>

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users