Display 2nd Textbox when option selected

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

    #1

    Display 2nd Textbox when option selected

    I have a select box with about 5 options.
    I need to have one of the options, when selected, display a second select
    box.
    The second select box is populated by a database and needs to be preloaded
    so the page doesnt refresh.

    How can this be done?

    I guess could have the second select box displayed but disabled and it would
    become active once the option is selected on the first select box.

    I just have no idea how to do this.

    Thanks in advance!




  • Martin Honnen

    #2
    Re: Display 2nd Textbox when option selected



    Targa wrote:
    [color=blue]
    > I have a select box with about 5 options.
    > I need to have one of the options, when selected, display a second select
    > box.
    > The second select box is populated by a database and needs to be preloaded
    > so the page doesnt refresh.
    >
    > How can this be done?
    >
    > I guess could have the second select box displayed but disabled and it would
    > become active once the option is selected on the first select box.
    >
    > I just have no idea how to do this.[/color]

    HTML 4 knows an attribute named disabled for HTML form controls, it is
    scripted as the property of the same name so to have a form that enables
    a select if a certain option of another select is selected have a look
    at the following example:

    <html>
    <head>
    <title>disablin g/enabling a form control</title>
    </head>
    <body>
    <form name="formName" >
    <select name="select1"
    onchange="if (this.selectedI ndex == 3) {
    this.form.eleme nts.select2.dis abled = false;
    }
    else {
    this.form.eleme nts.select2.dis abled = true;
    }">
    <option>optio n 1</option>
    <option>optio n 2</option>
    <option>optio n 3</option>
    <option>optio n 4</option>
    <option>optio n 5</option>
    </select>
    <select name="select2">
    <option>optio n 1</option>
    <option>optio n 2</option>
    <option>optio n 3</option>
    <option>optio n 4</option>
    <option>optio n 5</option>
    </select>
    <script type="text/javascript">
    document.forms. formName.elemen ts.select2.disa bled = true;
    </script>
    </form>
    </body>
    </html>

    Note that script is used to disable the select initially as a select
    disabled statically with HTML would mean the user needs JavaScript
    enabled to make use of the form.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Targa

      #3
      Re: Display 2nd Textbox when option selected

      Excellent example!
      Worked perfectly for me - Thanks!


      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:40827b31@o laf.komtel.net. ..[color=blue]
      >
      >
      > Targa wrote:
      >[color=green]
      > > I have a select box with about 5 options.
      > > I need to have one of the options, when selected, display a second[/color][/color]
      select[color=blue][color=green]
      > > box.
      > > The second select box is populated by a database and needs to be[/color][/color]
      preloaded[color=blue][color=green]
      > > so the page doesnt refresh.
      > >
      > > How can this be done?
      > >
      > > I guess could have the second select box displayed but disabled and it[/color][/color]
      would[color=blue][color=green]
      > > become active once the option is selected on the first select box.
      > >
      > > I just have no idea how to do this.[/color]
      >
      > HTML 4 knows an attribute named disabled for HTML form controls, it is
      > scripted as the property of the same name so to have a form that enables
      > a select if a certain option of another select is selected have a look
      > at the following example:
      >
      > <html>
      > <head>
      > <title>disablin g/enabling a form control</title>
      > </head>
      > <body>
      > <form name="formName" >
      > <select name="select1"
      > onchange="if (this.selectedI ndex == 3) {
      > this.form.eleme nts.select2.dis abled = false;
      > }
      > else {
      > this.form.eleme nts.select2.dis abled = true;
      > }">
      > <option>optio n 1</option>
      > <option>optio n 2</option>
      > <option>optio n 3</option>
      > <option>optio n 4</option>
      > <option>optio n 5</option>
      > </select>
      > <select name="select2">
      > <option>optio n 1</option>
      > <option>optio n 2</option>
      > <option>optio n 3</option>
      > <option>optio n 4</option>
      > <option>optio n 5</option>
      > </select>
      > <script type="text/javascript">
      > document.forms. formName.elemen ts.select2.disa bled = true;
      > </script>
      > </form>
      > </body>
      > </html>
      >
      > Note that script is used to disable the select initially as a select
      > disabled statically with HTML would mean the user needs JavaScript
      > enabled to make use of the form.
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]



      Comment

      Working...