在线等待,急!!

dsppcn 2003-11-11 11:32:49
如何在下拉框中(从数据库取出数据),选择一个内容,然后添加到文本框,然后再选,在添加到文本框,中间用分号分开,然后,对文本框中的内容进行分离,最后,对每个下拉框的内容添加相同的信息,如何处理呢?(vbscripit + sqlserver2000)
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacklinchen 2003-11-11
  • 打赏
  • 举报
回复
2。修改时,从表中调出其值, 通过split()进行分解, 然后放在下拉框中, 功能是一样的, 可增可删, 代码为:

<TD align=right width=220>
<select name="select1" size=10 style="width:240">
<option value="" disabled>====== 待选国家(地区) ======</option>
<%
dim rsc
set rsc=server.CreateObject("adodb.recordset")
sql=""
sql="select * from tbCountryInfo order by CountryID"
rsc.Open sql,conn,1,1
do while not rsc.EOF
ExAreas=split(rs("ImportedArea"),",")
i=0
for each ExArea2 in ExAreas
if trim(ExArea2)<>"" then
i=i+1
set rsa1=server.CreateObject("adodb.recordset")
sql=""
sql="select * from tbCountryInfo where CountryID="&cint(ExArea2)
rsa1.Open sql,conn,1,1
ExArea3=ExArea3&","&rsa1("CountryID")&" "&rsa1("CountryCnName")
end if
next
if instr(1,ExArea3,cstr(rsc("CountryID"))&" "&trim(rsc("CountryCnName")))<1 then
%>
<option value="<%=cstr(rsc("CountryID"))&" "&trim(rsc("CountryCnName"))%>"><%=cstr(rsc("CountryID"))&" "&trim(rsc("CountryCnName"))%></option>
<%
end if
rsc.MoveNext
loop
rsc.Close
set rsc=nothing
%>
</select>
</td>
<td width="80" align=center>
<label onClick="do_select()" style="cursor:hand"><font color="blue"><u>加---></u></font></label><br><br><br>
<label onClick="do_select2()" style="cursor:hand"><font color="blue"><u><---删</u></font></label>
</td>
<TD align=right width=190>
<select name="SelCountrys" size=10 style="width:240">
<option value="" disabled>====== 已选国家(地区) ======</option>
<%
ExArea=split(rs("ImportedArea"),",")
ImportedArea_o=""
i=0
for each ExArea1 in ExArea
if trim(ExArea1)<>"" then
i=i+1
set rsa=server.CreateObject("adodb.recordset")
sql=""
sql="select * from tbCountryInfo where CountryID="&cint(ExArea1)
rsa.Open sql,conn,1,1
ImportedArea_o=ImportedArea_o&","&rsa("CountryID")&" "&rsa("CountryCnName")
%>
<option value="<%=rsa("CountryID")&" "&rsa("CountryCnName")%>"><%=rsa("CountryID")&" "&rsa("CountryCnName")%></option>
<% rsa.Close
end if
next
%>
</select>
</td>
<%
str=""
str="function do_select() {" & vbCrlf & _
"if (document.form1.select1.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf&_
"for(var i=0;i<document.form1.select1.options.length;i++) {"&vbCrlf & _
"if(document.form1.select1.options(i).selected) {"&vbCrlf& _
"j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
"if (j > 0) {"&vbCrlf&_
"if (document.form1.select1.options[document.form1.select1.selectedIndex].value!='') {"&vbCrlf & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.options.length] = new Option(" & _
"document.form1.select1.options[document.form1.select1.selectedIndex].value," & _
"document.form1.select1.options[document.form1.select1.selectedIndex].value);"& vbCrlf
str=str&"document.form1.select1.options[document.form1.select1.selectedIndex] =null;" & vbCrlf &"}"& vbCrlf '&"}"& vbCrlf ' &"}"
str=str&"document.form1.ImportedArea.value=''" &vbCrlf
str=str&" for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
" document.form1.ImportedArea.value=document.form1.ImportedArea.value+','+document.form1.SelCountrys.options[i].value}"&"}"& vbCrlf &vbCrlf &"}"&vbCrlf &"}"
Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write str & vbCrlf & "</SCRIPT>"& vbCrlf

%>

<%
str=""
str="function do_select2() {" & vbCrlf & _
"if (document.form1.SelCountrys.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf&_
"for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
"if(document.form1.SelCountrys.options(i).selected) {"&vbCrlf& _
"j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
"if (j > 0) {"&vbCrlf&_
"if (document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value !='') {"&vbCrlf&_
"document.form1.select1.options[document.form1.select1.options.length] = new Option(" & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value," & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value);"& vbCrlf
'str=str&"if (len=document.form1.ImportedArea.indexOf(1,document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value)>0) {"& vbCrlf & _
' "document.form1.ImportedArea.value=document.form1.ImportedArea.substr(1,len)+document.form1.ImportedArea.substr(len+document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].length); }"& vbCrlf
str=str&"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex] =null;" & vbCrlf &"}"& vbCrlf '&"}"& vbCrlf ' &"}"
str=str&"document.form1.ImportedArea.value=''" &vbCrlf
str=str&" for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
"if (document.form1.SelCountrys.options[i].value !='') {"&vbCrlf & _
" document.form1.ImportedArea.value=document.form1.ImportedArea.value+','+document.form1.SelCountrys.options[i].value}"&"}"& vbCrlf &vbCrlf &"}"&vbCrlf &"}"&vbCrlf &"}"
Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write str & vbCrlf & "</SCRIPT>"& vbCrlf
%>

jacklinchen 2003-11-11
  • 打赏
  • 举报
回复
我是这样做的, 就是用两个下拉框, 然后在两个下拉框中可自由选择、删除,然后将选中的项目放到隐藏的文本框中。 很方便的, 由于代码较长, 得分成两个贴子了。

1。 增加时:

<TD align=right width=240>
<select name="select1" size=10 style="width:220">
<option value="" disabled>====== 待选国家(地区) ======</option>
<%
dim rsc
set rsc=server.CreateObject("adodb.recordset")
sql=""
sql="select * from tbCountryInfo order by CountryID"
rsc.Open sql,conn,1,1
do while not rsc.EOF
%>
<option value="<%=cstr(rsc("CountryID"))&" "&trim(rsc("CountryCnName"))%>"><%=cstr(rsc("CountryID"))&" "&trim(rsc("CountryCnName"))%></option>
<%
rsc.MoveNext
loop
rsc.Close
set rsc=nothing
%>
</select>
</td>
<td width="80" align=center>
<label onClick="do_select()" style="cursor:hand"><font color="blue"><u>加--></u></font></label><br><br><br>
<label onClick="do_select2()" style="cursor:hand"><font color="blue"><u><--删</u></font></label>
</td>
<%
str="function do_select() {" & vbCrlf & _
"if (document.form1.select1.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf & _
"for(var i=0;i<document.form1.select1.options.length;i++) {"&vbCrlf & _
"if(document.form1.select1.options(i).selected) {"&vbCrlf& _
"j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
"if (j > 0) {"&vbCrlf & _
"if (document.form1.select1.options[document.form1.select1.selectedIndex].value!='') {"&vbCrlf & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.options.length] = new Option(" & _
"document.form1.select1.options[document.form1.select1.selectedIndex].value," & _
"document.form1.select1.options[document.form1.select1.selectedIndex].value);"& vbCrlf '& _
Response.Write "<td align=center><SELECT id=SelCountrys name=SelCountrys size=10 style='width:220'><option value='' disabled> ====== 已选国家(地区) =====</option>"
Response.Write "</select></td>"

str=str&vbCrlf&"document.form1.select1.options[document.form1.select1.selectedIndex]=null;"&vbCrlf & _
"if (document.form1.select1.options.length > 1) {"&vbCrlf
str=str&vbCrlf & "}" & vbCrlf & "}" & vbCrlf & "}" & vbCrlf& "}" & vbCrlf '& "}" & vbCrlf
str=str&"document.form1.ImportedArea.value='';"&vbCrlf & _
"for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
"if (document.form1.SelCountrys.options[i].value !='') {"&vbCrlf & _
" document.form1.ImportedArea.value=document.form1.ImportedArea.value+','+document.form1.SelCountrys.options[i].value}"&vbCrlf &"}" &vbCrlf &"}"
Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write str & vbCrlf & "</SCRIPT>"& vbCrlf

%>

<%
str=""
str="function do_select2() {" & vbCrlf & _
"if (document.form1.SelCountrys.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf&_
"for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
"if(document.form1.SelCountrys.options(i).selected) {"&vbCrlf& _
"j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
"if (j > 0) {"&vbCrlf&_
"if (document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value !='') {"&vbCrlf&_
"document.form1.select1.options[document.form1.select1.options.length] = new Option(" & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value," & _
"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex].value);"& vbCrlf
str=str&"document.form1.SelCountrys.options[document.form1.SelCountrys.selectedIndex] =null;" & vbCrlf &"}" & vbCrlf &"}"& vbCrlf &"}"& vbCrlf '&"}"
str=str&"document.form1.ImportedArea.value='';"&vbCrlf & _
"for(var i=0;i<document.form1.SelCountrys.options.length;i++) {"&vbCrlf & _
"if (document.form1.SelCountrys.options[i].value !='') {"&vbCrlf & _
" document.form1.ImportedArea.value=document.form1.ImportedArea.value+','+document.form1.SelCountrys.options[i].value}"&vbCrlf &"}" &vbCrlf &"}"
Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write str & vbCrlf & "</SCRIPT>"& vbCrlf
%>

28,407

社区成员

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

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