Click to See Complete Forum and Search --> : Javascript Array


Venom77
12-02-2003, 01:57 PM
Hi Everyone,

I have a problem regarding inserting a value that is to be passed inside my javascript select drop down. This was my initial code:

catopt = new Array;
catopt[0] = "Select", "00";
catopt[1] = "Pieces", "0";
catopt[2] = "Release Notes", "2";
catopt[3] = "White Paper", "1";
catopt[4] = "Other", "9";

But when I pass the above form values, only the text gets passed and not the
value, like 00, 2, 0 ect...
So I changed my code to the below, so that those codes can be passed, new
code is:

catopt = new Array;
catopt[0] = new Option("Select", "00");
catopt[1] = new Option("Pieces", "0");
catopt[2] = new Option("Release Notes", "2");
catopt[3] = new Option("White Paper", "1");
catopt[4] = new Option("Other", "9");

writeln('<SELECT NAME="SelectPrimary" onChange="changeMenu(this.form)">');
tot = catopt.length;
for (i = 0; i < tot; i++)
writeln("<OPTION>" +catopt[i]);
writeln("</SELECT>");

But when I open the page in IE, the only text I see in my drop down is:
object, object, object, and in Netscape: [objectHTMLOptionElement], as if I
had inputed nothing.

I would greatly appreciate any help on this matter.

Thanks in advance!
Much Appreciated!

AdamGundry
12-02-2003, 02:04 PM
Use the second version of your code, and try this:

writeln('<OPTION value="' + catopt[i].value + '">' +catopt[i].text + '</OPTION>');

Adam

Venom77
12-02-2003, 04:14 PM
Wow that was a fast reply.

Thanks for the help Adam, that worked perfectly.