如何制作单选框的联动

qiftwxf 2008-11-28 02:02:02
是否的单选按钮
选是下边文本框为必填
选否下边的文本框不是必填

望高手指教
...全文
86 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
alandy 2008-11-28
function check(obj)
{
var len=obj.sex.length;
var user_name=obj.user_name.value;
if(obj.sex[0].checked)
{
if(user_name=="")
{
alert('请输入文本框内容');
user_name.focus();
return false;
}
}
return true;
}


</script>
<body>
<form name="form1" method="post" action="?" onsubmit="return check(this);" >
<input type="radio" name="sex" value="0" />是
<input type="radio" name="sex" value="1" />否
<input type="text" name="user_name">
<input type="submit" value="提交" >
</form>


</body>
回复
qiftwxf 2008-11-28
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="vbscript">
Function check() {
if(radio[0].checked) {
if (trim(form1.value)="" or isnull(form1.value)) {
msgbox("请在文本框输入")
Function = false
else
Function = true
}
}
}

</script>
</HEAD>
<BODY>
<form name="form1" action="" method="" submit="check()">
<INPUT type=radio name="radio" checked>是
<INPUT type=radio name="radio">否
<INPUT type=text name=textbox>
<INPUT type=submit>
</form>
</BODY>
</HTML>
回复
layers2323 2008-11-28
[Quote=引用 9 楼 qiftwxf 的回复:]
这个好像差不多,但是老是报错.
[/Quote]

把代码贴出来改改。
回复
qiftwxf 2008-11-28
不是菜单是单选框
回复
qiftwxf 2008-11-28
大致这样,没跑过,可能细节要改。


<script language='vbscript'>
Function check()
if(radio[0].checked) then
if (trim(form1.value)="" or isnull(form1.value)) then
msgbox("请在文本框输入")
Function = false
else
Function = true
end if
end if
End Function
</script>


<form name='form1' action='' method='' submit='check()'>
<INPUT type=radio name="radio" checked>是
<INPUT type=radio name="radio">否
<INPUT type=text name=textbox>
<INPUT type=submit>
</form>


这个好像差不多,但是老是报错.
回复
kmiaoer 2008-11-28
百度一下。级联菜单。很多例子
回复
qiftwxf 2008-11-28
很感谢大家回答
回复
layers2323 2008-11-28
大致这样,没跑过,可能细节要改。


<script language='vbscript'>
Function check()
if(radio[0].checked) then
if (trim(form1.value)="" or isnull(form1.value)) then
msgbox("请在文本框输入")
Function = false
else
Function = true
end if
end if
End Function
</script>


<form name='form1' action='' method='' submit='check()'>
<INPUT type=radio name="radio" checked>是
<INPUT type=radio name="radio">否
<INPUT type=text name=textbox>
<INPUT type=submit>
</form>
回复
草原可可 2008-11-28
有很多联动的 ajax 也可以做 比JS还简单
回复
草原可可 2008-11-28
像这样写个函数
<span class="f12px180b">再选择题库类别:<select size="1" class="wenbenkuang" name="szShi" onChange="info()">

function info(){

document.getElementById("sj").innerHTML="当前选择题库:<font color='#ff0000'>"+document.userinfo.szSheng.options[document.userinfo.szSheng.selectedIndex].text+"</font> 类别: <font color='#ff0000'> "+document.userinfo.szShi.options[document.userinfo.szShi.selectedIndex].text+"</font>";
document.userinfo.lbmc.value=document.userinfo.szSheng.options[document.userinfo.szSheng.selectedIndex].text;
}
回复
minwen369 2008-11-28

function val()
{
var dl=document.getElementById(下拉框名);
var txt=document.getElementById(文本框名)
if(dl.options[dl.selectedIndex].innerText=="是")
{
if(txt.value=="")
{
alert('请输入文本框内容');
txt.focus();
return false;
}
}
return true;
}


提交前用val()函数验证下就OK了!
回复
草原可可 2008-11-28
<%dim sql,i,j
dj = int(session("dj"))
set rs_d=server.createobject("adodb.recordset")
'response.Write(dj)
'response.End()
if dj = 1 then
sql="select * from test_lb where id=15 order by id"
elseif dj = 2 then
sql="select * from test_lb where id=15 or id=16 order by id"
else
sql="select * from test_lb order by id"
end if
'set rs_d=server.createobject("adodb.recordset")
'sql="select * from test_lb order by id"
rs_d.open sql,conn,1,1
%>

var selects=[];
selects['mr']=new Array(new Option('请选择子栏目……','mr'));
<%
for i=1 to rs_d.recordcount
%>
selects['<%=rs_d("id")%>']=new Array(
<%
set rs_x=server.createobject("adodb.recordset")
sql="select * from test_xlb where lbid="&rs_d("id")&" order by id"
rs_x.open sql,conn,1,1
if rs_x.recordcount>0 then
for j=1 to rs_x.recordcount

set rs_t=server.createobject("adodb.recordset")
sqll="select * from test_tm where xlbid="&rs_x("id")
rs_t.open sqll,conn,1,1
tmsl=rs_t.recordcount
rs_t.close


if j=rs_x.recordcount then
%>
new Option('<%=trim(rs_x("xlbmc"))%>--从<%=tmsl%>道题目中抽取--','<%=trim(rs_x("id"))%>'));
<% else
%>
new Option('<%=trim(rs_x("xlbmc"))%>--从<%=tmsl%>道题目中抽取--','<%=trim(rs_x("id"))%>'),
<%
end if
rs_x.movenext
next
else
%>
new Option('','0'));
<%
end if
rs_x.close

rs_d.movenext
next
rs_d.close

%>
回复
草原可可 2008-11-28
<select size="1" class="wenbenkuang" name="szSheng" onChange="chsel()">
<option value="xxx" selected>....请选择题库....</option>

<%do until rs_d.eof%>
<option value="<%=rs_d("id")%>"><%=rs_d("lbmc")%></option> <%
rs_d.movenext
loop

%>
</select>

function chsel(){
with (document.userinfo){
if(szSheng.value) {
szShi.options.length=0;
for(var i=0;i<selects[szSheng.value].length;i++){
szShi.add(selects[szSheng.value][i]);
}
}
}

document.getElementById("sj").innerHTML="当前选择题库:<font color='#ff0000'>"+document.userinfo.szSheng.options[document.userinfo.szSheng.selectedIndex].text+"</font> 类别: <font color='#ff0000'> "+document.userinfo.szShi.options[document.userinfo.szShi.selectedIndex].text+"</font>";
document.userinfo.lbmc.value=document.userinfo.szSheng.options[document.userinfo.szSheng.selectedIndex].text;
}
function IsDigit()
{
return ((event.keyCode >= 48) && (event.keyCode <= 57));
}

回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-11-28 02:02
社区公告
暂无公告