It is important to note that when you need to add items dynamically, you must
First Var newoption=new Option ("Item", "value");
And then Select.options.add (newoption);
In order to add it.
The code is as follows:
<HTML><Head><Scriptlanguage= "JavaScript"> functionChangesever () {varNewop1,newop2; //declaring two variables to add an option item Switch(Document.form1.select1.value)//determine the selected item, note that the value is not the selected item, the value of the selection { Case "LT": Newop1=NewOption ("Thunder Zone 1","LT1"); NEWOP2=NewOption ("Thunder Zone 2","LT2"); Break; Case "Ty": Newop1=NewOption ("Tianya 1 District","LT1"); NEWOP2=NewOption ("Tianya 2 District","LT2"); Break; } document.form1.select2.options.length=0; //to empty all the itemsDocument.form1.select2.options.add (NewOption ("Please select the appropriate server")); Document.form1.select2.options.add (NEWOP1); //Add ItemDocument.form1.select2.options.add (NEWOP2);}</Script></Head><Body><formname= "Form1"Method= "POST"Action=""> <Selectname= "Select1"OnChange= "Changesever ()">//Parent drop-down box<optionselected>Please select your area</option> <optionvalue= "LT">Thunder</option> <optionvalue= "Ty">End of the world</option> </Select> <P><Selectname= "Select2">//Sub drop -down box<option>Please select server</option> </Select></form></Body></HTML>
JS implementation of simple provincial and municipal cascade effect