JS implementation of simple provincial and municipal cascade effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.