一个二级联动代码,在网上档的。运行出现问题,本来是二级联动,那时能用,我改成了三级联动,可是班级的下拉矿不能显示。请大家指点。。。
javaScript:
function findObject(fName,initValue)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST","serch.jsp?findObject="+fName+"&initValue="+initValue,false);
xmlhttp.send();
document.getElementById(fName).innerHTML=bytes2BSTR(xmlhttp.responsebody);
}
vbScript:
Function bytes2BSTR(vIn)
dim i
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
serch.jsp
if(request.getParameter("findObject")!=null)
{
if (request.getParameter("findObject").equals("college"))
{
ResultSet rs = null;
try
{
out.print("<select name='college' onchange=javascript:findObject('special',this.value)>");
String sql = "select * from college ";
DataBase db = new DataBase();
db.connect();
db.stmt = db.conn.createStatement();
rs=db.stmt.executeQuery(sql);
while(rs.next()){
out.print( "<option value='' selected> </option>"+"<option value='"+rs.getString("c_num")+"'>"+new String(rs.getString("c_name").getBytes("ISO8859-1"))+"</option>");
}
out.print("</select>");
}
catch (Exception e){
}
finally{
try{
if (rs != null)
rs.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
if (request.getParameter("findObject").equals("special"))
{
ResultSet rqs = null;
try{
out.print("<select name='special' onchange=javascript:findObject1('class',this.value)>");
String sql = null;
if (request.getParameter("initValue").equals(""))
{
sql = "select * from sepcial";
}
else
{
sql = "select * from special where c_num='"+request.getParameter("initValue")+"'";
}
DataBase db = new DataBase();
db.connect();
db.stmt = db.conn.createStatement ();
rqs=db.stmt.executeQuery(sql);
while(rqs.next())
{
out.print("<option value='"+rqs.getString("sp_num")+"'>"+new String(rqs.getString("sp_name").getBytes("ISO8859-1"))+"</option>");
}
out.print("</select>");
}
catch (Exception e)
{
}
finally{
try{
if (rqs!= null)
rqs.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
if (request.getParameter("findObject").equals("class"))
{
ResultSet rqs = null;
try{
out.print("<select name='class' >");
String sql = null;
if (request.getParameter("initValue").equals(""))
{
sql = "select * from class";
}
else
{
sql = "select * from class where sp_num='"+request.getParameter("initValue")+"'";
}
DataBase db = new DataBase();
db.connect();
db.stmt = db.conn.createStatement ();
rqs=db.stmt.executeQuery(sql);
while(rqs.next())
{
out.print("<option value='"+rqs.getString("cl_num")+"'>"+new String(rqs.getString("cl_name").getBytes("ISO8859-1"))+"</option>");
}
out.print("</select>");
}
catch (Exception e)
{
}
finally{
try{
if (rqs!= null)
rqs.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
}
%>
<script language=vbscript src="bytetostr.js"></script>
<script language=javascript src="main.js"></script>
所属行业:<br>
<div id="college"></div>
所属明细行业:<br>
<div id="special"></div>
班级:
<div id="class"></div>
<script language="javascript">
findObject("college","");
findObject("special","");
findObject("class","");
</script>