
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