Jsp+javascript to create a level-connected menu

Source: Internet
Author: User
Tags array sql string sort stmt
javascript|js| Menu

<%@ 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: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.fde PT = t2.fno ORDER by T2.fname ";
 stmt=conn.createstatement ();
 rs=stmt.executequery (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;
&NBSP}
%>
Temp=<%=temp%>
function changelocation (ID) {
document.combo_box.city.length=0;//Initialize the length of level 2nd menu, subscript starting 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 equal, proves that there is a subset of input 1th level organizations in level 2nd, the total number of arr[] [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= ">"
<tr height= ">"
&LT;TD bgcolor= "#336699" class= "buttons" Align=center><font color= #ffffff > Department Selection </font></td>
&LT;TD bgcolor= "#336699" class= "buttons" Align=center><font color= #ffffff > Name Selection </font></td>
&LT;TD bgcolor= "#336699" class= "buttons" Align=center nowrap><font color= #ffffff > Add/Remove </font></td >
&LT;TD bgcolor= "#336699" class= "buttons" Align=center><font color= #ffffff > End Person </font></td>
</tr>
<tr>
<td>
<select multiple Id=prov name= "Prov" style= "width:150;height:200" class= "BGC" >
<option value= "0" > Please select Department---></option>
<%
String sqld= "SELECT * from Tdept";
Stmt=conn.createstatement ();
Rs=stmt.executequery (SQLD);
while (Rs.next ())
{
%>
<option name= "<%=rs.getstring (" FNO ")%>" ><%=rs.getstring ("fname")%></option>
<%
}
%>
</select>
</td>
<td>
<select multiple id=city style= "width:150;height:200" class= "BGC" >
</select>
</td>
&LT;TD nowrap align= "center" class= "BGC" >
<input type= "button" value= "<<" class= "buttons" >
<input type= "button" value= ">>" class= "buttons" >
</td>
<td>
<select multiple size= "ten" name= "List2" style= "width:150;height:200" class= "BGC" >
</select>
</td>
</tr>
<tr class= "BGC" >
&LT;TD colspan= "4" align= "center" ><input type= "button" Name= "Button1" class= "Buttons" value= "Selected! "></td>
</tr>
</table>
</form>

<script language= "JavaScript" >
Name move
function Move (Fbox, Tbox) {
var arrfbox = new Array ();
var arrtbox = new Array ();
var arrlookup = new Array ();
var i;
for (i = 0; i < tbox.options.length; i++) {
Arrlookup[tbox.options[i].text] = Tbox.options[i].value;
Arrtbox[i] = Tbox.options[i].text;
}
var flength = 0;
var tlength = arrtbox.length;
for (i = 0; i < fbox.options.length; i++) {
Arrlookup[fbox.options[i].text] = Fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value!= "") {
Arrtbox[tlength] = Fbox.options[i].text;
tlength++;
}
else {
Arrfbox[flength] = Fbox.options[i].text;
flength++;
}
}
Arrfbox.sort ();
Arrtbox.sort ();
fbox.length = 0;
tbox.length = 0;
var C;
for (c = 0; c < arrfbox.length; C + +) {
var no = new Option ();
No.value = Arrlookup[arrfbox[c]];
No.text = Arrfbox[c];
FBOX[C] = no;
}
for (c = 0; c < arrtbox.length; C + +) {
var no = new Option ();
No.value = Arrlookup[arrtbox[c]];
No.text = Arrtbox[c];
TBOX[C] = no;
}
}

</script>
</body>



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.