adding values to dropdown lists in javascript

E

Evan

I have searched high and low and am posting this question in the hope
that someone out there on the net can help me out. I am using a merge
of ASP and JavaScript.

My goal is to create 2 drop down lists. Both are populated from a
database using ASP, BUT the contents of the second list are dependant
on the selection of the first list. When the user selects the state in
the first list, then only the cities which reside in that state are
displayed in the second dropdown list.

I have this working to a point using the JavaScript command:
document.frmRegistration.cityName.options[0] = new Option("Perth");

The problem with this is that although it adds a display value, each
state has a stateID, which also needs to be included. In essence, the
line of code above, does this:
<option>Perth</option>

What I need it to do is this:
<option value="1">Perth</option>

How do I get the 'value' field to insert using javascript ?!?!?!?!

If anyone here knows, please PLEASE let me know... otherwise point me
in the right direction.

Thanks
 
K

kaeli

My goal is to create 2 drop down lists. Both are populated from a
database using ASP, BUT the contents of the second list are dependant
on the selection of the first list. When the user selects the state in
the first list, then only the cities which reside in that state are
displayed in the second dropdown list.

Does this help?

http://www.ipwebdesign.net/kaelisSpace/useful_dynamicSelects.html

--
--
~kaeli~
The best part of having kids is giving them back to their
parents.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
B

bruce

I have searched high and low and am posting this question in the hope
that someone out there on the net can help me out. I am using a merge
of ASP and JavaScript.

My goal is to create 2 drop down lists. Both are populated from a
database using ASP, BUT the contents of the second list are dependant
on the selection of the first list. When the user selects the state in
the first list, then only the cities which reside in that state are
displayed in the second dropdown list.

I have this working to a point using the JavaScript command:
document.frmRegistration.cityName.options[0] = new Option("Perth");

The problem with this is that although it adds a display value, each
state has a stateID, which also needs to be included. In essence, the
line of code above, does this:
<option>Perth</option>

What I need it to do is this:
<option value="1">Perth</option>

How do I get the 'value' field to insert using javascript ?!?!?!?!

If anyone here knows, please PLEASE let me know... otherwise point me
in the right direction.

Thanks

My work is all in IE, so I can only vouch for IE. I think that
document.frmRegistration.cityName.options[0].value="your
value"
seems to work for me.

You get "your value" from the other select box in the usual way
(document.frmRegistration.otherSelectBox.options[document.frmRegistratin.otherSelectBox.selectedIndex].value.
 
B

Bart Van der Donck

Evan said:
My goal is to create 2 drop down lists. Both are populated from a
database using ASP, BUT the contents of the second list are dependant
on the selection of the first list. When the user selects the state in
the first list, then only the cities which reside in that state are
displayed in the second dropdown list.
I have this working to a point using the JavaScript command:
document.frmRegistration.cityName.options[0] = new Option("Perth");
The problem with this is that although it adds a display value, each
state has a stateID, which also needs to be included. In essence, the
line of code above, does this:
<option>Perth</option>
What I need it to do is this:
<option value="1">Perth</option>

Taking your example as a starting point:
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top