下拉列表取值 传值问题

nettt 2012-06-14 04:57:08
下拉列表取值
我想从‘工序’列表中选择一个项目,然后‘工种’下拉列表中,显示该工序下的所有工种,不知道怎么写了
这是我现在的代码。
<td>工序code</td>
<td><select name="ProcessCode" id="ProcessCode">
<%
While (NOT procss.EOF)
%>
<option value="<%=(procss.Fields.Item("ProcessCode").Value)%>" <%If procss.Fields.Item("name").Value="解冻" Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(procss.Fields.Item("name").Value)%></option>
<%
procss.MoveNext()
Wend
If (procss.CursorType > 0) Then
procss.MoveFirst
Else
procss.Requery
End If
%>
</select></td>
</tr>
<%
if request.Form("ProcessCode") <>"" then
Set jobs = Server.CreateObject("ADODB.Recordset")
jobs_Source = "select JobCode,name from Man_jobs where jobtype= "&request.Form("ProcessCode")&" "
Response.Write(jobs_Source)
jobs.open jobs_Source, connm,1,1
end if
%>
<tr>
<td>工种</td>
<td><select name="jobs" id="jobs">
<%
While (NOT jobs.EOF)
%>
<option value="<%=(jobs.Fields.Item("jobcode").Value)%>" <%If jobs.Fields.Item("name").Value="班长" Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(jobs.Fields.Item("name").Value)%></option>
<%
jobs.MoveNext()
Wend
If (jobs.CursorType > 0) Then
jobs.MoveFirst
Else
jobs.Requery
End If
%>
</select></td>
...全文
238 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
velly 2012-06-15
  • 打赏
  • 举报
回复
AJAX有点慢,我一般是用JS实现,在后台程序生成工序+工种的完整JS数组,然后直接在浏览器执行即可

<script>var job=new Array();
<%
set rs1 = (提取工序数据)
for i = 0 to rs1.recordcount - 1
%>
job[<%=i%>]=new Array();
job[<%=i%>][0]='<%=rs1(工序)%>';
<%
set rs2 = (提取对应rs1(工序)的工种数据)
for j = 1 to rs2.recordcount - 1
job[<%=i%>][<%=j%>]='<%=rs1(工种)%>';
next
rs2.close
next
%>
function list1Onchanged(工序id){
var List1=document.getElementById("list1");
var List2=document.getElementById("list2");
while(List2.hasChildNodes()) List2.removeChild(List2.firstChild);
for(int i=0;i<job.length;i++){
if (job[i][0]==工序id){
var opt=document.createElement('option');
opt.value=工种id;
if (blSelect)opt.selected=true;
var cTxt=document.createTextNode(工种name);
opt.appendChild(cTxt);
List2.appendChild(opt);
}
}
}
</script>
nettt 2012-06-15
  • 打赏
  • 举报
回复
有没有例子,给我一个
实在是不会写
  • 打赏
  • 举报
回复
网上有这样例子的,动态的,搜索自己修改成自己的表名以及字段吧
nettt 2012-06-15
  • 打赏
  • 举报
回复
这段代码跑不出来,不知道那里有问题

<%
strSQLServerName = "192.168.8.78" '数据库服务器地址
strSQLDBUserName = "sa" '用户名
strSQLDBPassword = "PPP" ' '密码
strSQLDBName = "PP" '数据库名
'----------------------------------------------------------

Set connpaos = Server.CreateObject("ADODB.Connection")
connm = "Provider=SQLOLEDB.1;Persist Security Info=False;Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"
connpaos.Open connm

%>
<%
function DbCombox()
dim rs,sql,msg
sql = "select ProcessCode as ProcessCode,name as name from Man_processes"
set rs = connm.execute(sql)
response.Write("1")
while not rs.eof
msg = msg & "<option value=""" & rs("ProcessCode") & """>"&rs("ProcessCode")&"</option>"
rs.movenext
wend
rs.close
set rs = nothing
DbCombox = msg
End function

%>
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员登录</title>
</head>

<body>
<script language ="javascript" >
jobs = new Array();
<%
dim rs,sql,i
sql = "select job,name from LT.[paliu].[dbo].View_proc_jobs "
set rs = connm.execute(sql)
i = 0
while not rs.eof
%>
jobs[<%=i%>] =new Array("<%=rs("job")%>","<%=rs("job")%>");
<%
i = i + 1
rs.movenext
wend
rs.close
set rs = nothing
%>
function changeselect(selvalue){
var selvalue = selvalue;
var i;
document.form1.City.length = 0 ;
document.form1.City.options[document.form1.City.length] = new Option("请选择","");
for (i = 0 ;i <jobs.length;i++){
if(jobs[i][0]==selvalue){
document.form1.City.options[document.form1.City .length] = new Option(jobs[i][1],jobs[i][1]);
}
}
}

document.form1.City.options[document.form1.City.length] = new Option("请选择","");

</script>

<div align="center">
<form method="POST" action="sub.asp" name="form1">
<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%" id="table1" height="59">
<tr>
<td width="67" height="30" bgcolor="#D4D0C8"><b><font size="2">工序</font></b></td>
<td height="30" bgcolor="#D4D0C8"><select name="gongxu" size="1" id="gongxu" onchange ="changeselect(document.form1.Region.options[document.form1.Region.selectedIndex].value)">
<%=DbCombox()%></select></td>
</tr>
<tr>
<td width="67" height="30"><b><font size="2">工种</font></b></td>
<td height="30"><select name="gongzhong" size="1" id="gongzhong"></select></td>
</tr>
</table>
</form>
</div>

</body>
</html>
LittleMo_2012 2012-06-14
  • 打赏
  • 举报
回复
你这个是“两级联动”
你要结合ajax,第一个下拉框选中 onchange事件,ajax去取值,然后把值插入第二个下拉框

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧