Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I dynamically select Listbox item?

Status
Not open for further replies.

jww118

MIS
Feb 11, 2002
2
US
I have an 'edit entry' asp page. It allows a user to edit an entry they have in the database. Some of the data comes from 2 listboxes. I am trying to make the listbox automatically select entries, based on the data from the original database entry, so that if they don't want to change the data in the list boxes, the original data will still be in there. What would be the best way to go about doing this? I have tried using javascript, and the selectedIndex property, but no luck.
 
Let me know if this is what you were looking for...
Code:
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
  <select name=&quot;select&quot; size=&quot;1&quot; multiple>
    <option <%If MyData=&quot;list1&quot; then Response.Write(&quot;selected&quot;) end if%>>list1</option>
    <option <%If MyData=&quot;list2&quot; then Response.Write(&quot;selected&quot;) end if%>>list2</option>
  </select>
</form>

 
I kind of explained it badly in the first post. What I basically need to do is programmatically set the selected option in the listbox. I figured I could just do a

onLoad=&quot;this.selectedIndex=3&quot; or
onLoad=&quot;form1.List1.selectedIndex = 3&quot;

(3 is just for example...i would figure out what the number should be in the program.)

but this does nothing...the first option in the list still comes up first. Any ideas?
 
JWW,

Snowboardr's response should work for what you need..

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top