If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

dropdown list

I am having trouble with a dropdown list. I have a dropdownlist that updates another dropdown list. It does a refresh on the page and then the first dropdown list I select looses the value I selected..but the second dropdown list does retain the changes from the first. How do i give the first dropdown list that contains the OnChange() function back the value I selected? see code below...

'This is where I tried to reset the dropdown list back to what i selected..

'For Each objOption in ClientList.Options

For i = 0 to ClientList.Items.Count -1

If ClientList.InnerText = strClients Then
ClientList.SelectedIndex = i
End If
Next

%>
</select>
<br>
<%

' I also tried this... it didn't work either....
'Dim i
'If value <> "" Then
' For i = 0 To ClientList.Items.Count - 1
' If ClientList.Items(i).Value = Request.QueryString("CList") Then
' ClientList.SelectedIndex = i
' End If
' Next
'End If

A brief look at your code, it seems you are confusing javascript and ASP/VBScript. SelectedIndex is a property of the Select element in the client-side DOM. You cannot set these values in ASP. However, you have a couple options or techniques you can take advantage of here.

1) when the user submits the form, capture the selected option of the first list box. You don't need to process it but simply use it when looping thru your option tags. If the value of your option tag matches the value of the option submitted, add the SELECTED attribute to the option tag.

2) Use ASP to write out the javascript necessary to set the selected index for the proper option in your select element.

3) You can ride the latest technique train and process all this in AJAX. it will give you constant access to the client side form, process your data in real-time to the client, and avoid a visible round trip to the server (no page reloading). AJAX is actually pretty simple. It just requires a little knowlege of XML and familiarity with javascript parsing of XML and the document object.

Note: You should make it a practice to *not* switch back and forth between HTML and the ASP shortcut for the write method, <%= %>. This is poor practice for performance as it causes IIS to constantly switch back and forth between the ASP.DLL and the standard output. Anywhere you have the <%= %> directive, preceed that line with repsonse.write and concatenate your literals and variables.