Click to See Complete Forum and Search --> : Newbie, select list help please.....


davidbook
04-16-2003, 06:15 PM
I am a newbie, and am trying to populate a select list with data from an array, based on a previous select list option. here is what i have so far....
<script language = Javascript>
var Acura = new Array();
Acura[0]='Cl';
Acura[1]='MDX';
Acura[2]='RL';
Acura[3]='RSX';
Acura[4]='TL';

var Audi = new Array();
Audi[0]='A4';
Audi[1]='A6';
Audi[2]='A8';
Audi[3]='AllRoad';
Audi[4]='RS6';
Audi[5]='S6';
Audi[6]='S8';
Audi[7]='TT';

var BMW = new Array();
BMW[0]='3 Series';
BMW[1]='5 Series';
BMW[2]='7 Series';
BMW[3]='M3';
BMW[4]='M5';
BMW[5]='X5';
BMW[6]='Z4';
BMW[7]='Z8';
</script>

I need to get the value of "ONE" of these arrays into another select list (make/model for cars...)
<form>

<select name="Make" onChange="???">
<option value="Acura">Acura</option>
<option value="Audit">Audit</option>
<option value="BMW">BMW</option>
</select>

<select name="Model">
need to add option for each item in array....
</select>

I have tried every imaginable combo with tutuorials, etc. I just keep getting errors...
I need to pass the value from the Make Select list to a function, then have the function fill the Model Select list with the values in the array NAMED THE SAME as the Make selectedINdex.value....
Any help would be great...
David

DrDaMour
04-16-2003, 06:39 PM
that is definately a thinker, i'm halfway there, thought i'd post so you could look, and myabe you'll have some ingenuity.

<html>

<body>

<select name="worldwide" size="1" onChange="this.form.worldwide.options[this.form.worldwide.selectedIndex].value">
<option value="yes">HMmmmm
<option value="yes">HMmmmm
<option value="yes">HMmmmm
<option value="yes">HMmmmm

</select>

<script>
worldwide.size=4;
worldwide.options[1].text = "new text"
worldwide.options[1].value = "new value"

</script>

the .text is what is displayed, while the .value is what is the value passed on a submit. What seems to be missing, is you can't change the amount of options availible, that worldwide.size is definately not the answer. But i'll keep playing.

davidbook
04-16-2003, 06:43 PM
I am definitley closer, i have been able to figure out how the pass the first select lists value to a function.....
<select name="Make" onChange="fillModels(document.forms[0].Make.value)">

Now i am working on looping through the array to "fill the second list". The array to use has the same name as the value passed....
Thanks for helping...
David

DrDaMour
04-16-2003, 06:47 PM
yeah i got it, it was .length that is the amount of options
the script part of this will add the next options in the select box


<html>

<body>

<select name="worldwide" size="1" onChange="this.form.worldwide.options[this.form.worldwide.selectedIndex].value">
<option value="yes">HMmmmm


</select>

<script>
worldwide.length=2
worldwide.options[1].text = "new text"
worldwide.options[1].value = "new value"

</script>


so what i would do is
selectboxname.length = sizeofarraytobeadded
then a for loop
for(var i = 0; i < sizeofarraytobeadded;i++){
selectboxname.options[i].text = selectboxname.options[i].text = array[i];
}

that'll build your drop down list

DrDaMour
04-16-2003, 06:49 PM
<select name="Make" onChange="fillModels(document.forms[0].Make.value)">

would be better as

onChange="fillModels(document.forms[0].Make.options[selectedIndex].value)"