Forum Moderators: open

Message Too Old, No Replies

Arrayed select box and dynamic selections

         

RenardMF

4:57 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



I am trying to have a dynamic set of select boxes where choosing an item from a fixed list on one determines what the selections are in the other. The other items are stored in a javascript array. My problem is that the first and second select box both are stored in an input array with names like "name[]" and I am having trouble isolating specific select boxes. As of now in my onchange function I referring to them like this: document.form.elements['name[]'][0]. But when I try to get it to view the contents of the drop down box with the .options property it says that it doesn't exist.

Both lists are being fed by a database and occur several times in the same form to reflect different entries, hence the use of the arrayed names.

Any ideas?

DrDoc

5:14 am on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the exact code you're using to access the
options
object?

Fotiman

2:00 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



An easy way around this would just be to give your select boxes an id attribute and use getElementById instead of trying to access them through the form.

However, if you want to access them through the form, you need to correct this:

document.form.elements['name[]']

should be:

document.forms['yourFormName'].elements['name[]']

Note, document.forms, not document.form.

Then specify either the form name, or the form index.

Hope that helps.