View Single Post
  #11 (permalink)  
Old May 14th, 2004, 01:00 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Well, it's getting clearer. Take a look at this:

if (oList1.selectedIndex == -1){
  oList1.selectedIndex = 0;

At the end of the method, you are explicitly setting the selectedIndex to 0, the first item in the list.

Instead of that, call your function that Snib wrote and pass it the value of the item you want to select. First add the method to your page:

function PreselectMyItem(itemToSelect)
  for(myItem in myDropdown)
    if(myItem.text = ValueToSelect) /*if you want to
       // check the value,
       // use myItem.value instead of myItem.text*/
      myItem.selected = true;

and then preselect the item in the function you call onload

if (oList1.selectedIndex == -1){
 // oList1.selectedIndex = 0; not needed anymore

You should find how and what value you pass to SomeASPVariable, the server side ASP variable.

So, now when the page is requested, SomeASPVariable gets a server side value (again, that's up to you to do), and that value is embedded in the call to PreselectMyItem. Then PreselectMyItem makes sure the correct items gets selected.

Does this help? If it doesn't, can you upload a running example of the page somewhere? That is, a page with the real JavaScript and no ASP, so we can test it out a bit?

Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Kill You by KoRn (Track 14 from the album: Life Is Peachy) What's This?
Reply With Quote