469,271 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Populating Select Lists

This semester in school, I'm taking an Introduction to JavaScript class
online through my local community college. I'm having with an
assignment that requires you to set up two select lists. When you
select an option on the first list, it populates the second list with
specific information unique to that selection (Our example is to select
a state that would then populate a city list in the second). I can not
find any information or example to help with the script I need to
write, are there any suggestions?

Bryan

Oct 27 '06 #1
2 1226
ASM
br*************@gmail.com a écrit :
This semester in school, I'm taking an Introduction to JavaScript class
online through my local community college. I'm having with an
assignment that requires you to set up two select lists. When you
select an option on the first list, it populates the second list with
specific information unique to that selection (Our example is to select
a state that would then populate a city list in the second). I can not
find any information or example to help with the script I need to
write, are there any suggestions?
You could try to find infos about new Option()

new Option(value, text)
Example with :
- selct = selector (dropdown list)
- list = array of items (fruits, materials, states, towns ...)

function fillSelect(selct, list) {
// to empty selector
selct.length = 0;
// new options
for (var i=0; i<list.length; i++)
{
// new option : value and text
var o = new Option(list[i], list[i])
// grow selector adding new option
selct[selct.length] = o;
}
}

--
ASM
Oct 27 '06 #2

br*************@gmail.com wrote:
>to set up two select lists. When you
select an option on the first list, it populates the second list with
specific information unique to that selection (Our example is to select
a state that would then populate a city list in the second). I can not
find any information or example to help with the script I need to
write, are there any suggestions?
Where did you look? This homework question comes up so often that it's
difficult to avoid references to it.

Google: javascript +populate +"select box"

Oct 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bobsawyer | last post: by
1 post views Thread by msnews.microsoft.com | last post: by
1 post views Thread by Patrick.O.Ige | last post: by
1 post views Thread by Stephene | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.