Auto select drop down list after post back?

R

Rob Meade

Hi all,

I post back to my page if the form hasn't been submitted with the required
information. I would like to with a little javascript, auto-select an
option in the drop down list on my page.

The drop down list is called lstCountry

I will have in an ASP variable the country code which was the value of the
selected item when the form was posted...

I would like to do something like...

lstCountry.options[<%=strCountry%>].selected = true

I think however the value between the square brackets has to be a number
relating to the index of the option?

Can anyone help me with this please...

Regards

Rob
 
R

Randy Webb

Rob Meade said the following on 7/26/2006 6:11 PM:
Hi all,

I post back to my page if the form hasn't been submitted with the required
information. I would like to with a little javascript, auto-select an
option in the drop down list on my page.

Find the option, and add the selected attribute to it using ASP:

<option value="someValue" selected>Option Text</option>

No need to use client side scripting at all.
The drop down list is called lstCountry

I will have in an ASP variable the country code which was the value of the
selected item when the form was posted...

I would like to do something like...

lstCountry.options[<%=strCountry%>].selected = true

I think however the value between the square brackets has to be a number
relating to the index of the option?
Yes.

Can anyone help me with this please...

See Above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top