Dynamic Three-Level linkage menu, no refreshing, JSP implementation

Source: Internet
Author: User

Level 3 in total. Select Department Division through the department and speciality through the department.

<% @ Page Language = "Java" Import = "Java. util. *, java. Lang. *, java. SQL. *" pageencoding = "gb18030" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Script language = "JavaScript">
VaR deparmentcount; // three-level linkage menu code
Deparmentcount = 0;
VaR divisioncount;
Divisioncount = 0;
VaR specialitycount;
Specialitycount = 0
Department = new array ();
Division = new array ();
Speciality = new array ();
<%
System. Pub. oraclesql mydao = new system. Pub. oraclesql ();
Resultset rs = mydao.exe cquery ("select * from Division ");
Int I = 0;
For (Rs. Next ();! Rs. isafterlast (); RS. Next (), I ++) {%>
Division [<% = I %>] = new array ("<% = Rs. getstring ("division_name") %> "," <% = Rs. getstring ("department_id") %> "," <% = Rs. getstring ("ID") %> ");
<% }%>
Divisioncount = <% = I %>;

<%
System. Out. println ("Debug... 1 ");
Rs = mydao.exe cquery ("select * from speciality ");
I = 0;
For (Rs. Next ();! Rs. isafterlast (); RS. Next (), I ++) {%>
Speciality [<% = I %>] = new array ("<% = Rs. getstring ("speciality_name") %> "," <% = Rs. getstring ("division_id") %> "," <% = Rs. getstring ("ID") %> ");
<% }%>
Specialitycount = <% = I %>;

Function changedepartment (physical mentid ){
Document. form1.switch. value = "false ";
Document. form1.division. Length = 0;
VaR initialize mentid = initialize mentid;
VaR I;
For (I = 0; I <divisioncount; I ++ ){
If (Division [I] [1] = semantic mentid ){
Document. form1.division. Options [document. form1.division. Length] = New Option (Division [I] [0], Division [I] [2]);
}
}
Changedivision (document. form1.division. value );
}

Function changedivision (divisionid ){
Document. form1.switch. value = "false ";
Document. form1.speciality. Length = 0;
VaR divisionid = divisionid;
VaR I;
For (I = 0; I <specialitycount; I ++ ){
If (Speciality [I] [1] = divisionid ){
Document. form1.speciality. Options [document. form1.speciality. Length] = New Option (Speciality [I] [0], Speciality [I] [2]);
}
}
If (document. form1.speciality. length! = 0 ){
Document. form1.speciality. style. Visibility = 'visible ';
}
Else {
Document. form1.speciality. style. Visibility = 'den den ';
}
}

Function initialselect (){
Changedepartment (document. form1.department. Options [document. form1.department. selectedindex]. value );
}

</SCRIPT>
</Head>

<Body onload = "initialselect ();">
<Form name = "form1">
<Select name = "department" size = "1" id = "department" style = "width: 20%" onchange = "changedepartment (document. form1.department. options [document. form1.department. selectedindex]. value) ">
<%
Rs = mydao.exe cquery ("select * from Department ");
I = 0;
For (Rs. Next ();! Rs. isafterlast (); RS. Next (), I ++) {%>
<Option value = "<% = Rs. getstring (" ID ") %>"> <% = Rs. getstring ("department_name") %> </option>
<% }%>
</SELECT>
 
<Select name = "division" size = "1" id = "division" onchange = "changedivision (document. form1.division. Options [document. form1.division. selectedindex]. Value)">
</SELECT>

<Input type = "hidden" name = "Switch" value = "false">

<Select name = "speciality" size = "1">
</SELECT>
</Form>
</Body>
</Html>

After implementation, read the information in the three tables from the database. The generated HTML code is as follows:

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Script language = "JavaScript">
VaR deparmentcount; // three-level linkage menu code
Deparmentcount = 0;
VaR divisioncount;
Divisioncount = 0;
VaR specialitycount;
Specialitycount = 0
Department = new array ();
Division = new array ();
Speciality = new array ();

Division [0] = new array ("ccddd", "13", "100 ");

Division [1] = new array ("CCN", "14", "101 ");

Division [2] = new array ("cczz", "14", "102 ");

Division [3] = new array ("sdfgsdfg", "14", "103 ");

Division [4] = new array ("asdasdf", "14", "104 ");

Division [5] = new array ("zxcvzxcv", "14"," 106 ");

Division [6] = new array ("zxcvzv", "1", "107 ");

Division [7] = new array ("zxcvzxcv", "13", "108 ");

Division [8] = new array ("TV news", "2", "4 ");

Division [9] = new array ("TV photography", "2", "5 ");

Division [10] = new array ("Teaching and Research Section", "3", "6 ");

Division [11] = new array ("data center", "3", "7 ");

Division [12] = new array ("office", "3", "8 ");

Division [13] = new array ("zxcv", "14", "105 ");

Division [14] = new array ("Department of Communications Engineering", "1", "1 ");

Division [15] = new array ("Department of Electronic Information Engineering", "1", "2 ");

Division [16] = new array ("Department of Science and Art", "1", "3 ");

Division [17] = new array ("aaaa", "15", "109 ");

Divisioncount = 18;

Speciality [0] = new array ("ertwert", "101", "100 ");

Speciality [1] = new array ("vzxcvzxcv", "100", "101 ");

Speciality [2] = new array ("Zzz", "100", "102 ");

Speciality [3] = new array ("ASDF", "100", "103 ");

Speciality [4] = new array ("News Comment", "4", "1 ");

Speciality [5] = new array ("Network News", "4", "2 ");

Speciality [6] = new array ("Multimedia Technology", "1", "3 ");

Speciality [7] = new array ("art photography", "5", "4 ");

Speciality [8] = new array ("KKKK", "109", "104 ");

Specialitycount = 9;

Function changedepartment (physical mentid ){
Document. form1.switch. value = "false ";
Document. form1.division. Length = 0;
VaR initialize mentid = initialize mentid;
VaR I;
For (I = 0; I <divisioncount; I ++ ){
If (Division [I] [1] = semantic mentid ){
Document. form1.division. Options [document. form1.division. Length] = New Option (Division [I] [0], Division [I] [2]);
}
}
Changedivision (document. form1.division. value );
}

Function changedivision (divisionid ){
Document. form1.switch. value = "false ";
Document. form1.speciality. Length = 0;
VaR divisionid = divisionid;
VaR I;
For (I = 0; I <specialitycount; I ++ ){
If (Speciality [I] [1] = divisionid ){
Document. form1.speciality. Options [document. form1.speciality. Length] = New Option (Speciality [I] [0], Speciality [I] [2]);
}
}
If (document. form1.speciality. length! = 0 ){
Document. form1.speciality. style. Visibility = 'visible ';
}
Else {
Document. form1.speciality. style. Visibility = 'den den ';
}
}

Function initialselect (){
Changedepartment (document. form1.department. Options [document. form1.department. selectedindex]. value );
}

</SCRIPT>
</Head>

<Body onload = "initialselect ();">
<Form name = "form1">
<Select name = "department" size = "1" id = "department" style = "width: 20%" onchange = "changedepartment (document. form1.department. options [document. form1.department. selectedindex]. value) ">

<Option value = "2"> School of television and journalism </option>

<Option value = "3"> Computing Center </option>

<Option value = "1"> School of Engineering </option>

<Option value = "13"> fff </option>

<Option value = "14"> gdsf </option>

<Option value = "15"> zxcef </option>
 
</SELECT>
 
<Select name = "division" size = "1" id = "division" onchange = "changedivision (document. form1.division. Options [document. form1.division. selectedindex]. Value)">
</SELECT>

<Input type = "hidden" name = "Switch" value = "false">

<Select name = "speciality" size = "1">
</SELECT>
</Form>
</Body>
</Html>

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.