asp代码获取下拉框值,输入框变化
原来是这样的:有两个下拉框(主分类、次分类连动),对应的数据库表为class1和class2,还有一个输入框,提交后保存到数据库。现在想这样:当选择主分类中的某个选项,比...
原来是这样的:有两个下拉框(主分类、次分类连动),对应的数据库表为class1和class2,还有一个输入框,提交后保存到数据库。现在想这样:当选择主分类中的某个选项,比如选择XYZ,并且选项在class1中对应的ID为3,这时候想在下面的输入框中出现两行说明,比如,名称:****,价格:****,目的是提示用户输入相关内容。这个想法是否能实现,应该怎么处理,谢谢! 相关部分的代码如下:
<SELECT name="class1" onChange="changelocation(document.myform.class1.options
[document.myform.class1.selectedIndex].value)" size="1">
<OPTION selected value="">== 请选择主分类 ==</OPTION>
<%do while not rsclass.eof
%>
<OPTION value="<%=trim(rsclass("id"))%>"><%=trim(rsclass("class1"))%></OPTION>
<%
rsclass.movenext
loop
end if
rsclass.close
%>
</SELECT>
<SELECT name="class2"><OPTION selected value="">== 次分类 ==</OPTION></SELECT>
<tr>
<td height="26" colspan="2">
<p style="margin-left: 50px">信息内容:
<textarea rows="14" name="memo" id="memo" cols="71" onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput
(this.form)"></textarea>
<img border="0" src="image/plus.gif" width="20" height="20" onMouseOver="this.style.cursor='hand'"
onClick="sizeContent(5,'memo')" alt="增大输入框">
<img border="0" src="image/minus.gif" width="20" height="20" onMouseOver="this.style.cursor='hand'"
onClick="sizeContent(-5,'memo')" alt="缩小输入框">
<BR>
* 1500字以内 目前还可以写
<INPUT readonly type=text name=remLen size=4 maxlength=2 value="1500" style="border: 1 solid #888888">个字
<font color="#FF0000">*</font>
</td>
</tr>
<SCRIPT language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rsclass.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rsclass("class2"))%>","<%= trim(rsclass("class1"))%>","<%= trim(rsclass
("id"))%>");
<%
count = count + 1
rsclass.movenext
loop
rsclass.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.myform.class2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.class2.options[document.myform.class2.length] = new Option(subcat[i][0], subcat
[i][2]);
}
}
}
</SCRIPT> 展开
<SELECT name="class1" onChange="changelocation(document.myform.class1.options
[document.myform.class1.selectedIndex].value)" size="1">
<OPTION selected value="">== 请选择主分类 ==</OPTION>
<%do while not rsclass.eof
%>
<OPTION value="<%=trim(rsclass("id"))%>"><%=trim(rsclass("class1"))%></OPTION>
<%
rsclass.movenext
loop
end if
rsclass.close
%>
</SELECT>
<SELECT name="class2"><OPTION selected value="">== 次分类 ==</OPTION></SELECT>
<tr>
<td height="26" colspan="2">
<p style="margin-left: 50px">信息内容:
<textarea rows="14" name="memo" id="memo" cols="71" onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput
(this.form)"></textarea>
<img border="0" src="image/plus.gif" width="20" height="20" onMouseOver="this.style.cursor='hand'"
onClick="sizeContent(5,'memo')" alt="增大输入框">
<img border="0" src="image/minus.gif" width="20" height="20" onMouseOver="this.style.cursor='hand'"
onClick="sizeContent(-5,'memo')" alt="缩小输入框">
<BR>
* 1500字以内 目前还可以写
<INPUT readonly type=text name=remLen size=4 maxlength=2 value="1500" style="border: 1 solid #888888">个字
<font color="#FF0000">*</font>
</td>
</tr>
<SCRIPT language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rsclass.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rsclass("class2"))%>","<%= trim(rsclass("class1"))%>","<%= trim(rsclass
("id"))%>");
<%
count = count + 1
rsclass.movenext
loop
rsclass.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.myform.class2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.class2.options[document.myform.class2.length] = new Option(subcat[i][0], subcat
[i][2]);
}
}
}
</SCRIPT> 展开
1个回答
展开全部
可以在changelocation函数里添加,当触发onChange事件时,在memo文本框里显示内容:
function changelocation(locationid)
{
document.myform.memo.value = "名称:****\n价格:****";
document.myform.class2.length = 0;
function changelocation(locationid)
{
document.myform.memo.value = "名称:****\n价格:****";
document.myform.class2.length = 0;
追问
不好意,刚接触这个东东,问一下那在我这个例子中,触发所符合的条件的代码怎么写呢,拜托了!
追答
ID为3时才显示,其他的不显示?
if(locationid==3){
document.myform.memo.value = "名称:****\n价格:****";
}else{
document.myform.memo.value = "";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询