Click to See Complete Forum and Search --> : Array assignment issues


wfsaxton
03-04-2003, 08:44 PM
Pretty simple script. I want it to change the contents of a 2nd pulldown with regard to the first.

This function works:

function changePulldown() {

switch (document.join_form.tline.selectedIndex) {
case 0: document.join_form.tstop.options[0] = new Option ("Packard's Corner", "PKC");
break;
case 1: document.join_form.tstop.options[0] = new Option ("MIT", "MIT");
break;
default:
break;
}
}

This doesn't:

function changePulldown() {

var RedLineOptions = new Array(3);
var GreenLineOptions = new Array(3);

GreenLineOptions[0] = new Option ("Packard's Corner", "PKC");
RedLineOptions[0] = new Option ("MIT", "MIT");

switch (document.join_form.tline.selectedIndex) {
case 0: document.join_form.tstop.options = GreenLineOptions;
break;
case 1: document.join_form.tstop.options = RedLineOptions;
break;
default:
break;
}
}

I haven't done object oriented programming in a while, but I'd like to create the array of options first, then assign according to the switch statement.

Also, bonus points for anyone who can tell me how to create these arrays ONCE and have the function use the created arrays, no matter how many times the function is called.

khalidali63
03-05-2003, 06:12 AM
Take a look at this link,it might help you

http://68.145.35.86/skills/javascripts/MultipleListBoxResult3rdListBox.html

Cheers

Khalid

wfsaxton
03-06-2003, 06:24 PM
Hey Dave,

I know that will work, but I want to create the array first, then assign the entire array to the XXX.options array. Not individually assign the values to .options[0], .options[1], etc.

Khalid, i will check that out.

Just didn't want you two to think I fergot :)