Click to See Complete Forum and Search --> : How to add a value to a js Array


Klaws_wolverine
11-24-2003, 01:04 PM
Hello all,

I am creating a relational menu, where when the user selects a particular option in the first menu, it updates the contents/available selections in the second menu.

Problem is:
<option value="ValueVariable">Option1</option> HTML
siteopt[3] = new Option("Option1"); Javascript

In the javascript code, where does ValueVariable go?

Option1 is what the user sees, but If I want to send the value of this array element, how would I do so.

I would like the value to be 22 and what the user sees to be Alternate Fixes.

Any ideas?
Thanks

fredmv
11-24-2003, 01:09 PM
new Option("text", "value");

gil davis
11-24-2003, 01:29 PM
When you create a new Option the parameters are as follows:
new Option([text[, value[, defaultSelected[, selected]]]])
If you do not specify a value, the value default is the text.

Klaws_wolverine
12-02-2003, 12:59 PM
Could you put that in actual code as an example?

I don't understand the brackets: new Option([text[, value[, defaultSelected[, selected]]]])

Anyhow, I did this:

catopt = new Array;
catopt[0] = new Option("Select", "00");
catopt[1] = new Option("Pieces", "04");

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.

Can someone plz help me on this?

thx

gil davis
12-02-2003, 10:54 PM
<form name="f1">
<select name="s1">
</select>
</form>
<script>
document.f1.s1.options[0] = new Option("this is the text", "this is the value");
document.f1.s1.options[1] = new Option("this is the text", "this is the value");
</script>
You can also use
document.f1.s1.options[document.f1.s1.options.length]
if you don't want to specify which option it is.