changing select options based on previously selected options 
Author Message
 changing select options based on previously selected options

I need some straightforward client-side scripting so that the second
selection's options change based on what the user selected in the previous
selection.

Here's a form I'm using to practice:
<html>

<head>
</head>

<body>
<center>
<br>
My Form
<br>

<form name="myform" action="mysubmit.asp">

<br>
<select name="numero">
 <option value="1" SELECTED>1</option>
 <option value="2">2</option>
 <option value="3">3</option>
</select>
<br>

<br>
<select name="alphabet">
 <option value="A">A</option>
 <option value="B">B</option>
 <option value="C">C</option>
</select>
<br>

</form>
</center>
</body>
</html>

What code do I need to set up this form so that when a user selects option
"1" in the first selection, and the second selection's options are A,B,C;
but if the user chooses option "2" in the first selection, the choices in
the second selection become D,E, F?

Thanks, Amanda



Sat, 09 Aug 2003 23:07:36 GMT  
 changing select options based on previously selected options
take a look at
http://www.webtricks.com/SourceCode/default.cfm?Page=RelatedSelects.cfm


Quote:
> I need some straightforward client-side scripting so that the second
> selection's options change based on what the user selected in the previous
> selection.

> Here's a form I'm using to practice:
> <html>

> <head>
> </head>

> <body>
> <center>
> <br>
> My Form
> <br>

> <form name="myform" action="mysubmit.asp">

> <br>
> <select name="numero">
>  <option value="1" SELECTED>1</option>
>  <option value="2">2</option>
>  <option value="3">3</option>
> </select>
> <br>

> <br>
> <select name="alphabet">
>  <option value="A">A</option>
>  <option value="B">B</option>
>  <option value="C">C</option>
> </select>
> <br>

> </form>
> </center>
> </body>
> </html>

> What code do I need to set up this form so that when a user selects option
> "1" in the first selection, and the second selection's options are A,B,C;
> but if the user chooses option "2" in the first selection, the choices in
> the second selection become D,E, F?

> Thanks, Amanda



Sat, 09 Aug 2003 23:31:34 GMT  
 changing select options based on previously selected options
Slightly reduced:

<html>

<head>
<script>
function changeAlphabet (ind) {
  if (ind == '1') {
    document.myform.alphabet.options[0].value =
      document.myform.alphabet.options[0].text  = 'A';
    document.myform.alphabet.options[1].value =
      document.myform.alphabet.options[1].text  = 'B';
    document.myform.alphabet.options[2].value =
      document.myform.alphabet.options[2].text  = 'C';
  }
  else if (ind == '2') {
    document.myform.alphabet.options[0].value =
      document.myform.alphabet.options[0].text  = 'D';
    document.myform.alphabet.options[1].value =
      document.myform.alphabet.options[1].text  = 'E';
    document.myform.alphabet.options[2].value =
      document.myform.alphabet.options[2].text  = 'F';
  }

Quote:
}

</script>
</head>

<body>
<center>
<br>
My Form
<br>

<form name="myform" action="mysubmit.asp">

<br>
<select name="numero"
onchange="changeAlphabet(this.options[this.selectedIndex].value);">
 <option value="1" SELECTED>1</option>
 <option value="2">2</option>
</select>
<br>

<br>
<select name="alphabet">
 <option value="A">A</option>
 <option value="B">B</option>
 <option value="C">C</option>
</select>
<br>

</form>
</center>
</body>
</html>

You might want to check the FORM/SELECT section on JavaScript.FAQTs.com
to learn how to add new Options and delete them

Quote:

> I need some straightforward client-side scripting so that the second
> selection's options change based on what the user selected in the previous
> selection.

> Here's a form I'm using to practice:
> <html>

> <head>
> </head>

> <body>
> <center>
> <br>
> My Form
> <br>

> <form name="myform" action="mysubmit.asp">

> <br>
> <select name="numero">
>  <option value="1" SELECTED>1</option>
>  <option value="2">2</option>
>  <option value="3">3</option>
> </select>
> <br>

> <br>
> <select name="alphabet">
>  <option value="A">A</option>
>  <option value="B">B</option>
>  <option value="C">C</option>
> </select>
> <br>

> </form>
> </center>
> </body>
> </html>

> What code do I need to set up this form so that when a user selects option
> "1" in the first selection, and the second selection's options are A,B,C;
> but if the user chooses option "2" in the first selection, the choices in
> the second selection become D,E, F?

> Thanks, Amanda

--

        Martin Honnen
        http://javascript.faqts.com/
        http://home.t-online.de/home/martin.honnen/jsgoddies.html



Sat, 09 Aug 2003 23:43:25 GMT  
 changing select options based on previously selected options
Thanks, that works great!


Quote:
> Slightly reduced:

> <html>

> <head>
> <script>
> function changeAlphabet (ind) {
>   if (ind == '1') {
>     document.myform.alphabet.options[0].value =
>       document.myform.alphabet.options[0].text  = 'A';
>     document.myform.alphabet.options[1].value =
>       document.myform.alphabet.options[1].text  = 'B';
>     document.myform.alphabet.options[2].value =
>       document.myform.alphabet.options[2].text  = 'C';
>   }
>   else if (ind == '2') {
>     document.myform.alphabet.options[0].value =
>       document.myform.alphabet.options[0].text  = 'D';
>     document.myform.alphabet.options[1].value =
>       document.myform.alphabet.options[1].text  = 'E';
>     document.myform.alphabet.options[2].value =
>       document.myform.alphabet.options[2].text  = 'F';
>   }
> }
> </script>
> </head>

> <body>
> <center>
> <br>
> My Form
> <br>

> <form name="myform" action="mysubmit.asp">

> <br>
> <select name="numero"
> onchange="changeAlphabet(this.options[this.selectedIndex].value);">
>  <option value="1" SELECTED>1</option>
>  <option value="2">2</option>
> </select>
> <br>

> <br>
> <select name="alphabet">
>  <option value="A">A</option>
>  <option value="B">B</option>
>  <option value="C">C</option>
> </select>
> <br>

> </form>
> </center>
> </body>
> </html>

> You might want to check the FORM/SELECT section on JavaScript.FAQTs.com
> to learn how to add new Options and delete them



Sun, 10 Aug 2003 01:19:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. changing select options based on text value in another field

2. remove method for options not removing selected option.

3. <option Selected> based on variable

4. Programatically setting the SELECTED OPTION of a SELECT

5. Setting the selected option of a select box in code

6. Suppressing IE selecting option by letter on SELECT dropdowns

7. How to determine the selected option in a Select tag

8. How to dynamically select option in select element?

9. URGENT: changing HTML SELECT OPTIONs with VBScript

10. Changing the option values in Select Control

11. changing HTML SELECT OPTIONs with VBScript

12. add option to select list

 

 
Powered by phpBB® Forum Software