这样的程序如何做呀?是否有源代码以供参考?

xuallen 2003-08-24 09:35:17
在数据库中有两列
"型号" "产品"
A 1
A 2
A 3
B 4
B 5
C 6
C 7
我将型号列绑定到选择框中,想实现当选择A,右边相应的ListBox框中就显示对应的1,2,3,再选择其中一个后可以删除。
这样的程序如何写呢?
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuya 2003-08-24
  • 打赏
  • 举报
回复
参考以下:
这个是数据库版的
//page.asp
<%
type1 = Request.QueryString("type1")
type2 = Request.QueryString("type2")
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
SQL = "SELECT * FROM [type1]"
Rs1.Open SQL,Conn,3,3
If Rs1.EOF and Rs1.BOF Then
Response.Write "没有一级分类"
Else
Set tid = Rs1("id")
Set ttype1 = Rs1("type1")
Response.Write "<select name='type1' id='type1' onchange=javascript:location.href='page.asp?id=" & tid & "&type1='+type1.value; class='formsize'>"
Response.Write "<option value=''>--------</option>"
Do While NOT Rs1.EOF
Response.Write "<option value='" & tid & "'"
If Int(type1) = Int(Rs1("id")) Then
Response.Write " selected"
sel = True
End If
Response.Write">" & ttype1 & "</option>" & chr(10) & chr(13)
Rs1.MoveNext
Loop
Response.Write "</select>"
End If
Rs1.Close
Response.Write "<font color='red'>/</font>"
If sel <> True Then
Response.Write "请选择上级分类"
Else
SQL = "SELECT * FROM [type2] WHERE [type1]=" & type1
Rs1.Open SQL,Conn,3,3
If Rs1.EOF and Rs1.BOF Then
Response.Write "没有二级分类"
Response.Write "<input type='hidden' name='type2' value=''>"
Else
Set tid = Rs1("id")
Set ttype2 = Rs1("type2")
Response.Write "<select name='type2' id='type2' class='formsize'>"
Response.Write "<option value=''>--------</option>"
Do While NOT Rs1.EOF
Response.Write "<option value='" & tid & "'"
If Int(type2) = Int(Rs1("id")) Then
Response.Write " selected"
selok = True
End If
Response.Write">" & ttype2 & "</option>" & chr(10) & chr(13)
Rs1.MoveNext
Loop
Response.Write "</select>"
End If
Rs1.Close
End If
Set Rs1 = Nothing
%>

/////////////////
<script language="JavaScript">
function TableShow(){
var url1,DeName
DeName=document.form1.Type1.value;
url1="ErrorList.jsp?DeName="+DeName;
form1.action =url1;
form1.submit()
}
</script>

<select name="Type1" onChange="javascript:TableShow();">
<option value="1" <%if (TypeShow.equals("1")) out.print("selected");%>>通信费错单</option>
</select>

每change一次就提交一次

//////////////

<script language=javascript>
function ch(selectedids,n)
{
var selectedvalue=selectedids
var i
var t=0
document.form1.s2.length=0
for(i=0;i<n;i++)
{
if(subcat[i][0]==selectedvalue)
{
document.form1.s2.options[t]=new Option(subcat[i][1],subcat[i][2])
t=t+1
}
}
}
function check()
{
if (document.form1.s1.options.selectedIndex==0)
{
alert("请先选择类别")
document.form1.s1.focus()
return false
}
return true
}
</script>
xuya 2003-08-24
  • 打赏
  • 举报
回复
...
<%
s=request.form("选择框名")
sql="select distinc 型号 from 表名"
rs.open sql,conn,3,3
%>
选择型号:<select>
<%
while not rs.eof
if rs("型号")=s then
%>
<option selected><%=rs("型号")<option>
<%
else
%>
<option><%=rs("型号")<option>

<%
rs.movenext
wend
sql2="select 型号 from 表名 where 型号='"&s&"'"
rs2.open sql2,conn,3,3
%>
相应的产品:
<select>
<%
for i=0 to rs2.field.count-1
%>
<option><%=rs2(i)%></option>
<%
rs.movenext
next
%>
</select>
<%
set rs=nothing
set rs2=nothing
rs.close
rs2.close
set conn=nothing
conn.close
...
%>
...
xuallen 2003-08-24
  • 打赏
  • 举报
回复
也就是说在从列表中选择机型大类后,后面的“S1”列表会自动列出对应的项
需要调用onchange()事件吧?
<%
response.write "<select name='Model' id='Model' onChage='addText()'>"
response.write "<option selected='selected' value=''>请选择</option>"
do while not rs1.eof
response.write "<option value="& rs1("Cata") &">" & rs1("Cata") & chr(13)
rs1.movenext
loop
rs1.close
set rs1=nothing
response.write "</select>"
%>
<td width="25%" height="47"><select size="1" name="S1" multiple>
luok 2003-08-24
  • 打赏
  • 举报
回复
应该不是多难,你自己准备怎么实现?

贴出你的代码来,我们看看。

28,390

社区成员

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

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