Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Populating Listbox with Javascript

Status
Not open for further replies.

Razzie33

Technical User
Oct 3, 2000
9
US
Hi-

Ive been trying to get this to work but i cant

i have 2 fields and would like to populate the second field based on the first field's content using javascript ( so that there will be no return trip to the server)

say the fields are CarMake and CarModel
CarModel will reflect what is chosen as the make (eg. Toyota -- Camry, Rav4. Volkswagon- Beetle, etc)

i have the two fields on the form.

in the onFocus for CarMake i have:

Code:
 list = new Array ("BMW","Toyota","Volkswagon");
select = document.forms[0].CarMake;
len = list.length;
select.length = len;
for ( i = 0; i < len; i++) {
	CarMake.options[ i ].text = list [ i ]  ;
	CarMake.options[ i ].value = list [ i ] ;
		}
and in the onChange i have:
Code:
array = new Array
if (selection == &quot;BMW&quot;) {
		new Array  (&quot;Z3&quot;,&quot;Z5&quot;);
		} else if (selection == &quot;Toyota&quot;) {
	 new Array  (&quot;Rav4&quot;,&quot;Camry&quot;);
		}
	} else if (selection == &quot;Volkswagon&quot;) {
	 new Array  (&quot;Beetle&quot;,&quot;Jetta&quot;);
		}		
pick = document.forms[0].CarModel;
len = list.length;
pick.length = len;
for ( i = 0; i < len; i++) {
	CarModel.options[ i ].text =array [ i ]  ;
	CarModel.options[ i ].value = array [ i ] ;
		}
i keep getting &quot;undefined&quot; in the box when i make a change.
i dont think the bottom part is right for declaring how to populate the CarModel field but it is the only thing i use that i get some kind of an input.

and advice?

Thank you,
Kara
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top