JavaScript implementation three level linkage menu

Source: Internet
Author: User
Tags split
Javascript

Company someone to, write a, put up, have to copy go to use it, the following is the first option of value and text is a worthwhile way, the following is a different way to paste.

Run Code Box

<form method= "POST" name= "test" ><select name= "Select1" ></select><select name= "Select2" > </select><select name= "Select3" ></select></form><script language= "JavaScript" >< !--//copyright Siginie (siginie@hotmail.com), Www.3ad.cnvar arrtext = new Array (5); var arrvalue = new Array ( Arrtext.length); function objsetoption (Select1, Select2, select3) {this.select1 = Select1;this.select2 = Select2; This.select3 = Select3;} arrtext[0]= New Objsetoption ("Option 1:", "Select 2_1:, select 2_2:", "Select 3_1:, select 3_2:"); arrtext[1] = new Objsetoption ("Thesis: 1", "Language: 1, mathematics : 2, English: 3 "," Middle School: 2, High School: 3 "); arrtext[2] = new Objsetoption (" Example: 2 "," Display B2_1: Value b2_1, display b2_2: Value B2_2 "," Show B3_1: Value B3_1, display b3_2: Value b3_2 "); arrtext[3] = new Objsetoption (" Show C: Value C "," Display C2_1: Value c2_1, display c2_2: Value C2_2 "," Show C3_1: Value C3_1, display c3_2: Value C3_2 "); arrtext[4] = new Objsetoption ("Show D: Value D", "Show D2_1: Value d2_1, display d2_2: Value D2_2", "Show D3_1: Value D3_1, display d3_2: Value D3_2"); arrtext[5] = new Objsetoption ("Show E : Value E "," Display E2_1: Value e2_1, display e2_2: Value E2_2 "," Show E3_1: Value E3_1, display e3_2: Value E3_2 "); function Select () {var eltSelect1 = Document.test.select1;var EltSelect2 = Document.test.select2;var EltSelect3 = Document.te St.select3;var ArrSelect1, ArrSelect2, Arrselect3;var arrData1, ArrData2, Arrdata3;with (eltSelect1) {var strselect = Options[selectedindex].value;} for (i = 0;i < Arrtext.length;i + +) {ArrSelect1 = Arrtext[i].select1;arrdata1 = Arrselect1.split (":"); if (arrdata1[1] = = Strselect) {arrSelect2 = (arrtext[i].select2). Split (","); for (j = 0;j < arrselect2.length;j++) {arrData2 = arrselect2[ J].split (":"); with (eltSelect2) {length = Arrselect2.length;options[j].text = Arrdata2[0];options[j].value = arrdata2[ 1];} ArrSelect3 = (ARRTEXT[I].SELECT3). Split (","); for (j = 0;j < arrselect3.length;j++) {arrData3 = Arrselect3[j].split (": "); with (eltSelect3) {length = Arrselect3.length;options[j].text = Arrdata3[0];options[j].value = Arrdata3[1];}} Break;}}} function init () {var eltSelect1 = Document.test.select1;var EltSelect2 = Document.test.select2;var eltSelect3 = document. test.seLect3;var ArrSelect1, ArrSelect2, Arrselect3;var arrData1, ArrData2, arrdata3;if (eltSelect1!= undefined && elts Elect2!= undefined && eltSelect3!= undefined) {with (EltSelect1) {length = arrtext.length;for (i = 0;i < Arrtex T.length;i + +) {ArrSelect1 = Arrtext[i].select1;arrdata1 = Arrselect1.split (":"); options[i].text = Arrdata1[0];options [I].value = Arrdata1[1];}} With (eltSelect2) {arrSelect2 = (arrtext[0].select2). Split (","); length = arrselect2.length;for (i = 0;i < Length;i + +) { ArrData2 = Arrselect2[i].split (":"); options[i].text = Arrdata2[0];options[i].value = Arrdata2[1];} With (ELTSELECT3) {arrSelect3 = (ARRTEXT[0].SELECT3). Split (","); length = arrselect3.length;for (i = 0;i < Length;i + +) { ARRDATA3 = Arrselect3[i].split (":"); options[i].text = Arrdata3[0];options[i].value = Arrdata3[1];}}} Init ();//--></script>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]



Related Article

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.