Example code for creating a cascading menu Using jsp + javascript

Source: Internet
Author: User

Copy codeThe Code is as follows: <% @ page import = "java. util. Date, yava. fileapp. *, java. SQL .*;"
ContentType = "text/html; charset = GB2312" pageEncoding = "GB2312"
%>
<Style>
. F9 {font-size: 9pt ;}
. Bgc {background-color: # AECAF9; color: # 0033FF}
. Buttons {font-family: Arial; font-size: 13px; font-weight: bold; background-color: #6796E4; color: white; border-top: solid 2px # AACAFB;
Border-bottom: solid 1px #4E7DC1;
Border-left: solid 1px # AECAF9;
Border-right: solid 1px # 5679BD;
Padding: 1px;
Margin: 0px ;}
</Style>
<Script language = "JavaScript">
<! --
Function rv ()
{
Var val = "";
For (I = 0; I <combo_box.list2.length; I ++ ){
Val + = "," + combo_box.list2 [I]. value;
}
If (val. charAt (0) = ","){
Val = val. substr (1, val. length );
}
Opener. form1.frecname. value = val;
Self. close ();
}

// -->
</SCRIPT>
<Body leftmargin = "0" topmargin = "0" marginwidth = "0" marginheight = "0">
<Jsp (preferred for SUN Enterprise Applications): useBean id = "user" scope = "session" class = "yava. fileapp. UserBean"/>
<%
CDataSource ds = new CDataSource (); // data connection Bean instance
Java. SQL. Connection conn = ds. getConnection ();
Java. SQL. Statement stmt = null;
Java. SQL. ResultSet rs = null;
CDataCheck dc = new CDataCheck ();
%>

<%
String sqlu = "SELECT t1.fno, t1.fname, t2.fname AS fdept FROM tuser t1 left outer join TDept t2 ON t1.fdept = t2.fno order by t2.fname ";
Stmt = conn. createStatement ();
Rs1_stmt.exe cuteQuery (sqlu );
%>
<Script language = Javascript>
Arr = new Array ();
<% Int temp = 0;
While (rs. next ())
{
%>
Arr [<% = temp %>] = new Array ("<% = rs. getString ("fname") %> "," <% = rs. getString ("fdept") %> ");
<%
Temp = temp + 1;
}
%>
Temp = <% = temp %>;
Function ChangeLocation (id ){
Document. combo_box.city.length = 0; // initialize the length of the 2nd-level menu. The subscript starts from 0.
Var I = 0;
Document. combo_box.city.options [0] = new Option (-------,);
For (I = 0; I <temp; I ++ ){
If (arr [I] [1] = id) {// if they are equal, it is proved that there is a subset of the 2nd-level organization input in level 1st, and arr [total number] [Department]
Document. combo_box.city.options [document. combo_box.city.length] = new Option (arr [I] [0], arr [I] [0]);
}
}
}
</Script>

<Form name = "combo_box">
<Table border = "0" cellspacing = "0" cellpadding = "0" height = "210" width = "59">
<Tr height = "24">
<Td bgcolor = "#336699" class = "buttons" align = center> <font color = # ffffff> select a department </font> </td>
<Td bgcolor = "#336699" class = "buttons" align = center> <font color = # ffffff> name selection </font> </td>

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.