ASP中判断单选按钮是否被选中的问题,数据库中共有7到选择题目,当7道选择题目没有做完时候,不能提交表单
<FORMaction="result.asp"id="FORM1"method="post"name="FORM1"><Palign="center"><spancla...
<FORM action="result.asp" id="FORM1" method="post" name="FORM1" >
<P align="center"> <span class="unnamed1"><%
i=1
rs.movefirst
do while not rs.eof%> </span>
<P align="center"><span class="unnamed1"> <%=rs("question")%> </span></P>
<div align="center">
<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width="35%" bordercolor="#0099FF">
<TR bgcolor="#99CCFF">
<TD style="WIDTH: 50%" width="49%" class="unnamed1">
<INPUT name=ans<%=i%> type="radio" value="A" id="ans<%=i%>" >
<%=rs("A")%> </TD>
</TR>
<TR bgcolor="#CCCCFF">
<TD width="49%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="B" id="ans<%=i%>">
<%=rs("B")%> </TD>
</TR>
<TR bgcolor="#99CCFF">
<td width="51%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="C" id="ans<%=i%>">
<%=rs("C")%> </td>
</TR>
<TR bgcolor="#CCCCFF">
<TD width="49%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="D" id="ans<%=i%>">
<%=rs("D")%> </TD>
</TR>
</TABLE>
<span class="unnamed1"><%
i=i+1
rs.movenext
loop
%>
</span></div>
<div align="center"><span class="unnamed1"></P></span></div>
<P align="center"> </P>
<P align=center> <span class="unnamed1">
<INPUT id=submit1 name=submit1 type=submit value="提交" onclick="ck()">
<INPUT id=reset1 name=reset1 type=reset value="重填">
</span></P>
</FORM> 展开
<P align="center"> <span class="unnamed1"><%
i=1
rs.movefirst
do while not rs.eof%> </span>
<P align="center"><span class="unnamed1"> <%=rs("question")%> </span></P>
<div align="center">
<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width="35%" bordercolor="#0099FF">
<TR bgcolor="#99CCFF">
<TD style="WIDTH: 50%" width="49%" class="unnamed1">
<INPUT name=ans<%=i%> type="radio" value="A" id="ans<%=i%>" >
<%=rs("A")%> </TD>
</TR>
<TR bgcolor="#CCCCFF">
<TD width="49%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="B" id="ans<%=i%>">
<%=rs("B")%> </TD>
</TR>
<TR bgcolor="#99CCFF">
<td width="51%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="C" id="ans<%=i%>">
<%=rs("C")%> </td>
</TR>
<TR bgcolor="#CCCCFF">
<TD width="49%" class="unnamed1">
<input name=ans<%=i%> type="radio" value="D" id="ans<%=i%>">
<%=rs("D")%> </TD>
</TR>
</TABLE>
<span class="unnamed1"><%
i=i+1
rs.movenext
loop
%>
</span></div>
<div align="center"><span class="unnamed1"></P></span></div>
<P align="center"> </P>
<P align=center> <span class="unnamed1">
<INPUT id=submit1 name=submit1 type=submit value="提交" onclick="ck()">
<INPUT id=reset1 name=reset1 type=reset value="重填">
</span></P>
</FORM> 展开
2个回答
展开全部
在表单form标签上加onsubmit="return check()"然后在script标签范围内写一个check函数,函数的内容就是检查每一组radio按钮是不是都有值value,如果没全有就提示“请先把所有题目都选择答案”,然后return false,如果都有值了就return true或者不写,就OK了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script language=javascript>
function ck() {
for(var i=0;i<4;i++) {
if(!isSelected($("ans" + (i+1)))) {
alert("第【"+ (i + 1) + "】题未做,请答完题再提交!");
return false;
}
}
return true;
}
function isSelected(obj) {
for(var i=0;i<obj.length;i++) {
if(obj[i].checked==true)
return true;
}
return false;
}
function $(name) {
return document.getElementsByName(name);
}
</script>
function ck() {
for(var i=0;i<4;i++) {
if(!isSelected($("ans" + (i+1)))) {
alert("第【"+ (i + 1) + "】题未做,请答完题再提交!");
return false;
}
}
return true;
}
function isSelected(obj) {
for(var i=0;i<obj.length;i++) {
if(obj[i].checked==true)
return true;
}
return false;
}
function $(name) {
return document.getElementsByName(name);
}
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询