dynamic options in select boxes?

T

Thomas Damgaard

Hi,

I need to have two <SELECT> boxes: "brand" and "model". The user should
first select brand. Then the other select box should contain the options
dependend of what user chose in "brand". I figure this is something with
making some arrays containing models or something. Do any of you have an
example of how this can be done? I have tried to google for it, but dont
really know what to search for, so I get lousy results :(
 
M

Michael Winter

on 13/11/2003:
Hi,

I need to have two <SELECT> boxes: "brand" and "model". The user should
first select brand. Then the other select box should contain the options
dependend of what user chose in "brand". I figure this is something with
making some arrays containing models or something. Do any of you have an
example of how this can be done? I have tried to google for it, but dont
really know what to search for, so I get lousy results :(

SELECT elements (represented by a Select object) have a property
called 'options'. This is an array that contain Option objects and
represents the options listed by the SELECT element. You can create
Option objects using the 'new' keyword and then append them to the
Select object on your page:

document.myForm.myMenu.options[ document.myForm.myMenu.length ] = new
Option ( 'option-text', 'option-value' );

If you want to re-build a Select menu completely, you can set the
'length' property of the 'options' array to zero.

document.myForm.myMenu.options.length = 0;

Look for information on the Select and Option objects. Try here:
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/
It warns that v1.3 is obsolete (it is), but I haven't finished reading
about the Document Object Model (DOM) used by more recent versions,
and v1.3 is still supported, anyway.

Mike
 
T

Thomas Damgaard

Michael said:
SELECT elements (represented by a Select object) have a property
called 'options'. This is an array that contain Option objects and
represents the options listed by the SELECT element. You can create
Option objects using the 'new' keyword and then append them to the
Select object on your page:

document.myForm.myMenu.options[ document.myForm.myMenu.length ] = new
Option ( 'option-text', 'option-value' );

If you want to re-build a Select menu completely, you can set the
'length' property of the 'options' array to zero.

document.myForm.myMenu.options.length = 0;

Look for information on the Select and Option objects. Try here:
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/
It warns that v1.3 is obsolete (it is), but I haven't finished reading
about the Document Object Model (DOM) used by more recent versions,
and v1.3 is still supported, anyway.

Ok.
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top