javascript级联菜单,数据从数据库中获取
1.html代码:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*" %> <html>
<head>
<!--
放置javascript代码
-->
</head> <body style="font-size: 12px;" bgcolor="eeeeee">
<form name="form1" action="SpecialityRelation_Insert.jsp" method="get">
<img onclick="history.go(-1);" src="../../images/back_blue.gif" onmousemove="this.src='../../images/back_red.gif';" onmouseout="this.src='../../images/back_blue.gif'" style="cursor:hand;">
<hr> <%
String logicalclass_name = request.getParameter("name");
String logicalclass_id = request.getParameter("logicalclass_id");
%> <input name="logicalclass_id" value="<%=logicalclass_id%>" type="hidden">
<table border="1px">
<tr>
<td width="100px">教学班名称</td>
<td width="300px">
<input class="MyInputBox" name="name" value="<%=logicalclass_name%>" style="background:'#dddddd';" size="50" readonly/>
</td>
</tr>
<tr>
<td>所在专业</td>
<td>
<select class="MySelect" name="department" size="1" id="department" onChange="changeDepartment(document.form1.department.options[document.form1.department.selectedIndex].value)">
<%
rs = myDao.execQuery("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 class="MySelect" 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 class="MySelect" name="speciality" id="speciality" size="1" onChange="changeSpeciality(document.form1.speciality.options[document.form1.speciality.selectedIndex].value)"></select> <select class="MySelect" name="Grade" id="Grade" size="1" onChange="changeGrade(document.form1.Grade.options[document.form1.Grade.selectedIndex].value)">
</select> <select class="MySelect" name="ObjectID" size="1">
</select> </td>
</tr> <tr>
<td>说明</td>
<td><textarea name="other" class="MyTextArea" name="other" cols="48" rows="10"></textarea></td>
</tr> <tr>
<td colspan="2" align="right">
<img src="../../images/submit_blue.gif" onmousemove="this.src='../../images/submit_red.gif';" onmouseout="this.src='../../images/submit_blue.gif'" style="cursor:hand;" onclick="document.form1.submit();">
</td>
</tr>
</table>
</form>
</body>
</html>
2.javascript代码:
2.javascript代码
<script language="javascript"> var DeparmentCount; //三级联动菜单代码
DeparmentCount = 0;
var DivisionCount;
DivisionCount = 0;
var SpecialityCount;
SpecialityCount = 0; //GradeCount = 0;
ObjectIDCount = 0;
Department = new Array();
Division = new Array();
Speciality = new Array();
//Grade = new Array();
ObjectID = new Array(); <%
system.pub.oraclesql myDao = new system.pub.oraclesql();
ResultSet rs = myDao.execQuery("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")%>"); <%
}//for
%> DivisionCount = <%=i%>;
<%
System.out.println("debug....1");
rs = myDao.execQuery("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")%>"); <%
}//for
%>
SpecialityCount = <%=i%>; <%
rs = myDao.execQuery("select distinct speciality_id,grade,object_id,name from student t,object o where o.id= t.object_id");
i=0;
for(rs.next();!rs.isAfterLast();rs.next(),i++)
{
%> ObjectID[<%=i%>] = new Array("<%=rs.getString("speciality_id")%>","<%=rs.getString("grade")%>","<%=rs.getString("object_id")%>","<%=rs.getString("name")%>"); <%
}//for
%> ObjectIDCount = <%=i%>; function changeDepartment(DepartmentId)
{
document.form1.Switch.value="false";
document.form1.division.length = 0;
var DepartmentId = DepartmentId;
var i;
for (i=0;i < DivisionCount; i++)
{
if (Division[i][1] == DepartmentId)
{
document.form1.division.options[document.form1.division.length] = new Option(Division[i][0], Division[i][2]);
}
}
changeDivision(document.form1.division.value);
if(document.form1.division.length!=0)
{
document.form1.division.style.visibility = 'visible';
}
else
{
document.form1.division.style.visibility = 'hidden';
} } 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 = 'hidden';
document.form1.Grade.style.visibility = 'hidden';
document.form1.ObjectID.style.visibility = 'hidden'; }
changeSpeciality(document.form1.speciality.value);
} function changeSpeciality(SpecialityID)
{
document.form1.Switch.value="false";
document.form1.Grade.length = 0;
var SpecialityID = SpecialityID;
var i,j;
var flag = 0;
for (i=0;i < ObjectIDCount; i++)
{
if(ObjectID[i][0] == SpecialityID)
{
for(j=0,flag=0;j<document.form1.Grade.length;j++)
{
if(document.form1.Grade.options[j].value==ObjectID[i][1])
{
flag = 1;
break;
}
}
if(flag!=1)
{
document.form1.Grade.options[document.form1.Grade.length] = new Option(ObjectID[i][1], ObjectID[i][1]);
}
}
}
if(document.form1.Grade.length!=0)
{
document.form1.Grade.style.visibility = 'visible';
}
else
{
document.form1.Grade.style.visibility = 'hidden';
document.form1.ObjectID.style.visibility ='hidden';
}
changeGrade(document.form1.Grade.value);
} function changeGrade(GradeID)
{
document.form1.Switch.value="false";
document.form1.ObjectID.length = 0;
var GradeID = GradeID;
var i;
for (i=0;i < ObjectIDCount; i++)
{
if(ObjectID[i][1] == GradeID && ObjectID[i][0] == document.form1.speciality.value)
{
document.form1.ObjectID.options[document.form1.ObjectID.length] = new Option(ObjectID[i][3],ObjectID[i][2]);
}
}
if(document.form1.ObjectID.length!=0)
{
document.form1.ObjectID.style.visibility = 'visible';
}
else
{
document.form1.ObjectID.style.visibility = 'hidden';
}
} function initialSelect()
{
changeDepartment(document.form1.department.options[document.form1.department.selectedIndex].value);
} </script>
javascript级联菜单,数据从数据库中获取的更多相关文章
- JSP的数据从数据库中获取导入type=date的input标签中
jsp 页面最开始加上 <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> & ...
- Django Form 实时从数据库中获取数据
修改 models.py 添加 class UserType(models.Model): caption = models.CharField(max_length=32) 执行命令,生成数据库 p ...
- 关于EntityFramework 更新数据记录时字段全部更新问题和不从数据库中获取直接更新记录
一.一直对这个比较疑惑感觉只修改一条数据记录的一个字段结果更新Savechages后跟踪生成sql竟然是全部被修改,感觉微软怎么这么傻,总觉得会有其它方式可以只更新部分字段,但一直没有找到相关设置,最 ...
- 使用python读取配置文件并从mysql数据库中获取数据进行传参(基于Httprunner)
最近在使用httprunner进行接口测试,在传参时,用到了三种方法:(1)从csv文件中获取:(2)在config中声名然后进行引用:(3)从函数中获取.在测试过程中,往往有些参数是需要从数据库中获 ...
- insert 一条数据 然后拿出这条数据在数据库中生成的ID
[insert 一条数据 然后拿出这条数据在数据库中生成的ID] <insert id="insert" parameterType="management&quo ...
- MOOC(14)- 从数据库中获取预期结果
数据库中的预期结果写的是SQL语句 从表格中读取到SQL语句,再去数据库获取真正的预期结果 # -*- coding: utf-8 -*- # @Time : 2020/2/18 9:50 # @Fi ...
- ASP.NET MVC使用jQuery来POST数据至数据库中
学习ASP.NET MVC程序,结合jQuery客户端代码,Post数据至数据库去.Insus.NET今天写一个完整性的例子. 在数据库中,创建一个表[dbo].[TestUser]: 既然是把数据存 ...
- PostgreSQL数据库中获取表主键名称
PostgreSQL数据库中获取表主键名称 一.如下表示,要获取teacher表的主键信息: select pg_constraint.conname as pk_name,pg_attribute. ...
- php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中
php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...
随机推荐
- Apache Kylin安装部署
0x01 Kylin安装环境 Kylin依赖于hadoop大数据平台,安装部署之前确认,大数据平台已经安装Hadoop, HBase, Hive. 1.1 了解kylin的两种二进制包 预打包的二进制 ...
- 为django的python manage.py加自定义命令
计划在开发软件的过程中, 每次可以自己加入测试数据,这样就可以每次作全新的测试了. 将这个初始化django modules数据命令,将在manage.py里是最合适的. 下面我们就来实现吧. 参考文 ...
- GrideVlew提供点击按钮添加新数据,单击项目修改,长按删除功能
package com.example.wang.myapplication; import android.app.AlertDialog; import android.content.Dialo ...
- 转:springboot(二):web综合开发
web开发 spring boot web开发非常的简单,其中包括常用的json输出.filters.property.log等 json 接口开发 在以前的spring 开发的时候需要我们提供jso ...
- Vue.js中 watch 的高级用法
假设有如下代码: <div> <p>FullName: {{fullName}}</p> <p>FirstName: <input type=&q ...
- 15:链表中倒数第K个节点
/** * 面试题15:链表中倒数第K个节点 * 输入一个链表,输出该链表中倒数第k个结点. */ public class _15_linked_K { public static void mai ...
- 采用Post请求的方式提交参数并导出excel
一般情况下,我们都是采用get请求的方式导出excel.例如采用如下方式: var exportUrl = '/xxx;'; window.open(exportUrl); 导出excel所需的逻辑参 ...
- Mermaid 学习
基础 在 VS code 中安装插件 Markdown Preview Mermaid Support,则便可支持 Mermaid 流程图 flowchart graph LR; A-->B; ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property(2-sat)
E. National Property time limit per test 1 second memory limit per test 512 megabytes input standard ...
- NetCore+Dapper WebApi架构搭建(五):Swagger构建WebApi界面
上一节讲解了仓储的依赖注入,想必现在都可以通过构造函数依赖注入直接调用 但是WebApi只是提供一个接口调用,为了方便我们的操作,我们得给他加上一个图形化界面工具,使用Swagger WebApi项目 ...