dynamic options in select boxes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Damgaard

    dynamic options in select boxes?

    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 :(

    --
    Yours
    Thomas Damgaard


  • Michael Winter

    #2
    Re: dynamic options in select boxes?

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

    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:

    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

    --
    Michael Winter
    M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)


    Comment

    • Thomas Damgaard

      #3
      Re: dynamic options in select boxes?

      Michael Winter wrote:[color=blue]
      > 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/...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.
      >[/color]

      Ok.
      Thanks!


      --
      Med venlig hilsen
      Thomas Damgaard


      Comment

      Working...