87,910
社区成员
发帖
与我相关
我的任务
分享
function checkform(arg){
var els = document.form.elements;
for(var i=arg;i<els.length;i++){
switch(els[i].name){
case "a3":
if(document.form.a3.options.value.length < 1){
alert("请选择所在区域!");
window.location.href = "#a3";
return false;
};
break;
case "a4text":
if(selectother("a4id","a4text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a4text";
return false;
};
break;
case "a6text":
if(selectother("a6id","a6text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a6text";
return false;
};
break;
case "a7text":
if(selectother("a7id","a7text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a7text";
return false;
};
break;
case "a8text":
if(selectother("a8id","a8text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a8text";
return false;
};
break;
case "a9text":
if(selectother("a9id","a9text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a9text";
return false;
};
break;
case "a11text":
if(selectother("a11id","a11text") == 0){
alert("请输入其他项内容!");
window.location.href = "#a11text";
return false;
};
break;
case "b19text":
if(selectother("b19id","b19text") == 0){
alert("请输入其他项内容!");
window.location.href = "#b19text";
return false;
};
break;
case "d1text":
if(selectother("d1id","d1text") == 0){
alert("请输入其他项内容!");
window.location.href = "#d1text";
return false;
};
break;
case "d2text":
if(selectother("d2id","d2text") == 0){
alert("请输入其他项内容!");
window.location.href = "#d2text";
return false;
};
break;
case "a15":
if(select2("a15") != 2){
alert("请选择两项答案!");
window.location.href = "#a15";
return false;
};
break;
case "c3":
if(select2("c3") != 2){
alert("请选择两项答案!");
window.location.href = "#c3";
return false;
};
break;
case "c10":
if(mulselother("c10mtext","c10") == 0){
alert("请答完所有的题!");
window.location.href = "#c10";
return false;
}
break;
case "e3":
if(mulselother("e3mtext","e3") == 0){
alert("请答完所有的题!");
window.location.href = "#e3";
return false;
}
break;
case "f2":
if(mulselother("f2mtext","f2") == 0){
alert("请答完所有的题!");
window.location.href = "#f2";
return false;
}
break;
case "g2":
break;
case "g3":
break;
case "submit":
break;
default:
if(check_els(els[i]) == 0){
alert("请答完所有的题!");
window.location.href='#'+ els[i].name;
return false;
};
break;
}
}
};
function selectother(arg1,arg2){
var els1=document.getElementById(arg1);
if(els1.checked){
var els2 = document.getElementsByName(arg2);
var len = els2[0].value.length;
if(len < 1){
return 0;
}
else{
return len;
}
}
else{
return 1;
}
};
function select2(arg1){
var num = 0;
var els2 = document.getElementsByName(arg1);
for(var k=0;k<els2.length;k++){
if(els2[k].checked){
++num;
}
};
return num;
};
function mulselother(arg1,arg2){
var els1 = document.getElementById(arg1);
var len = els1.value.length;
if(len > 0){
return len;
}
else{
var num = 0;
var tmpels = document.getElementsByName(arg2);
for(var k=0;k<tmpels.length;k++){
if(tmpels[k].checked){
++num;
}
}
return num;
}
};
function check_els(el){
var sType = el.type;
switch(sType){
case "hidden":
return 1;
break;
default:
var tmpels = document.getElementsByName(el.name);
var num = 0;
for(var k=0;k<tmpels.length;k++){
if(tmpels[k].checked){
++num;
}
}
return num;
}
};
function allans(){
var els = document.form.elements;
for(var i=0;i<els.length;i++){
if(check_els(els[i]) == 0){
alert("请答完所有的题!")
return false;
break;
}
}
};
function check_els(el){
var tmpels = document.getElementsByName(el.name);
var num = 0;
for(var k=0;k<tmpels.length;k++){
if(tmpels[k].value.length > 0){
++num;
}
return num;
}
};
<SCRIPT LANGUAGE=javascript>
<!--
function chk() {
//-------------------检查第一部分
if(cal("r1")==0){
alert("请选择第一部分答案!"); window.location.href='#S1'; return false;
}
//-------------------检查第二部分
if(cal("r2")==0){
alert("请选择第二部分答案!"); window.location.href='#S2'; return false;
}
if (document.getElementById("t2").value==""){
alert("请填写第二部分中的[其他]!"); window.location.href='#S2'; return false;
}
//-------------------检查第三部分
if(cal("c3")==0){
alert("请选择第三部分中至少一个答案!"); window.location.href='#S3'; return false;
}
//-------------------检查第四部分
if(cal("c4")==0){
alert("请选择第四部分中至少一个答案!"); window.location.href='#S4'; return false;
return false;
}
if (document.getElementById("t4").value==""){
alert("请填写第四部分中的[其他]!!"); window.location.href='#S4'; return false;
}
//-------------------检查第五部分
if(cal("c5")!=2){
alert("第五部分中必须选择其中的2个答案!!"); window.location.href='#S5'; return false;
}
}
function cal(s){
var c = document.getElementsByName(s);
var num=0;
for(var i=0; i<c.length;i++){
if (c[i].checked){++num;}
}
return num
}
//-->
</SCRIPT>
<form method=post action="xxx.asp" name=frm onsubmit='javascript:return chk()'>
<a name=S1>
<div id=S1>
1)全部是radio<br>
<%
for i=1 to 3
Response.Write "<input type=radio id=r1 name=r1>问题1-"&i&"<br>"
next
%>
</div></a>
<hr>
<a name=S2>
<div id=S2>
2)一组radio + 一项"其他"选项,"其他"选项用text让手工输入;<br>
<%
for i=1 to 3
if i=3 then
Response.Write "其他<input type=text id=t2 name=t2>问题2-"&i
else
Response.Write "<input type=radio id=r2 name=r2>问题2-"&i&"<br>"
end if
next
%>
</div></a>
<hr>
<a name=S3>
<div id=S3>
3)全部是checkbox;<br>
<%
for i=1 to 3
Response.Write "<input type=checkbox id=c3 name=c3>问题3-"&i
next
%>
</div></a>
<hr>
<a name=S4>
<div id=S4>
4)一组checkbox + 一项"其他"选项,"其他"选项用text让手工输入;<br>
<%
for i=1 to 3
if i=3 then
Response.Write "其他<input type=text id=t4 name=t4>问题2-"&i
else
Response.Write "<input type=checkbox id=c4 name=c4>问题4-"&i&"<br>"
end if
next
%>
</div></a>
<hr>
<a name=S5>
<div id=S5>
5)全部是checkbox, 只让并且必须选2项;<br>
<%
for i=1 to 3
Response.Write "<input type=checkbox id=c5 name=c5>问题5-"&i&"<br>"
next
%>
</div>
</a>
<input type=submit id=b name=b value='提交' onclick="javascript:return chk();">
</form>
<SCRIPT LANGUAGE=javascript>
<!--
function chk() {
//-------------------检查第一部分
if(cal("r1")==0){
alert("请选择第一部分答案!");
return false;
}
//-------------------检查第二部分
if(cal("r2")==0){
alert("请选择第二部分答案!");
return false;
}
if (document.getElementById("t2").value==""){
alert("请填写第二部分中的[其他]!"); return false;
}
//-------------------检查第三部分
if(cal("c3")==0){
alert("请选择第三部分中至少一个答案!");
return false;
}
//-------------------检查第四部分
if(cal("c4")==0){
alert("请选择第四部分中至少一个答案!");
return false;
}
if (document.getElementById("t4").value==""){
alert("请填写第四部分中的[其他]!!"); return false;
}
//-------------------检查第五部分
if(cal("c5")!=2){
alert("第五部分中必须选择其中的2个答案!!");
return false;
}
}
function cal(s){
var c = document.getElementsByName(s);
var num=0;
for(var i=0; i<c.length;i++){
if (c[i].checked){++num;}
}
return num
}
//-->
</SCRIPT>
<form method=post action="xxx.asp" name=frm onsubmit='javascript:return chk()'>
<div id=S1>
1)全部是radio<br>
<%
for i=1 to 3
Response.Write "<input type=radio id=r1 name=r1>问题1-"&i&"<br>"
next
%>
</div>
<hr>
<div id=S2>
2)一组radio + 一项"其他"选项,"其他"选项用text让手工输入;<br>
<%
for i=1 to 3
if i=3 then
Response.Write "其他<input type=text id=t2 name=t2>问题2-"&i
else
Response.Write "<input type=radio id=r2 name=r2>问题2-"&i&"<br>"
end if
next
%>
</div>
<hr>
<div id=S3>
3)全部是checkbox;<br>
<%
for i=1 to 3
Response.Write "<input type=checkbox id=c3 name=c3>问题3-"&i
next
%>
</div>
<hr>
<div id=S4>
4)一组checkbox + 一项"其他"选项,"其他"选项用text让手工输入;<br>
<%
for i=1 to 3
if i=3 then
Response.Write "其他<input type=text id=t4 name=t4>问题2-"&i
else
Response.Write "<input type=checkbox id=c4 name=c4>问题4-"&i&"<br>"
end if
next
%>
</div>
<hr>
<div id=S5>
5)全部是checkbox, 只让并且必须选2项;<br>
<%
for i=1 to 3
Response.Write "<input type=checkbox id=c5 name=c5>问题5-"&i&"<br>"
next
%>
</div>
<input type=submit id=b name=b value='提交' onclick="javascript:return chk();">
</form>
<SCRIPT LANGUAGE=javascript>
<!--
function chk() {
var c = document.getElementsByName("aaa");
var num=0;
for(var i=0; i<c.length;i++){
if (c[i].checked){++num;}
}
if(num==2){
if (c[4].checked){
if (document.getElementById("ttt").value==""){
alert("请填写其他选项!"); return false;
}
else{alert("合格");}
}
else{alert("合格");}
}
else{
alert("只能选择其中的2个,且必须选2个");
return false;
}
}
//-->
</SCRIPT>
<%
for i=0 to 4
if i=4 then
Response.Write "<input type=checkbox id='aaa' name='aaa'>其他选项<input type='text' id='ttt' name='ttt'><br>"
else
Response.Write "<input type=checkbox id='aaa' name='aaa'>问题"&i+1&"<br>"
end if
next
%>
<BR>
<input type=button id=b name=b value='检查' onclick="javascript:return chk();">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>dhtml.checkbox.multipleSelected.html</title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<input type="checkbox" name="myGroup" id="cbx1" /><label for="cbx1">选项 1</label>
<input type="checkbox" name="myGroup" id="cbx2" /><label for="cbx2">选项 2</label>
<input type="checkbox" name="myGroup" id="cbx3" /><label for="cbx3">选项 3</label>
<input type="checkbox" name="myGroup" id="cbx4" /><label for="cbx4">选项 4</label>
<input type="checkbox" name="myGroup" id="cbx5" /><label for="cbx5">选项 5</label>
<input type="button" id="btnOK" value="OK" />
</body>
<script type="text/javascript">
<!--
Array.prototype.indexOf = function(target)
{
var result = -1;
for (var i=0; i<this.length; i++)
{
if (this[i] == target)
{
result = i;
break;
}
}
return result;
};
function selectItem()
{
if (this.checked)
{
if (aCounter.length == iMax)
{
var lastItem = document.getElementById(aCounter.pop());
lastItem.checked = false;
}
aCounter[aCounter.length] = this.id;
}
else
{
var index = aCounter.indexOf(this.id);
aCounter.splice(index, 1);
}
//alert(aCounter);
}
var iMax = 2;
var aCounter = new Array();
var cGroup = document.getElementsByName("myGroup");
for (var i=0; i<cGroup.length; i++)
{
cGroup[i].onclick = selectItem;
}
var oBtn = document.getElementById("btnOK");
oBtn.onclick = function()
{
if (aCounter.length == iMax)
{
alert("您选择了" + aCounter);
}
else
{
alert("请至少选择两项,谢谢!");
}
};
//-->
</script>
</html>
<SCRIPT LANGUAGE=javascript>
<!--
function chk() {
var c = document.getElementsByName("aaa");
var num=0;
for(var i=0; i < c.length;i++){
if (c[i].checked){++num;}
}
if(num==2){
if (document.getElementById("ttt").value==""){
alert("请填写其他选项!"); return false;
}
else{alert("合格");}
}
else{
alert("只能选择其中的2个,且必须选2个");
return false;
}
}
//-->
</SCRIPT>
<%
for i=0 to 4
Response.Write "<input type=checkbox id='aaa' name='aaa'>问题"&i+1&"<br>"
if i=4 then
Response.Write "<input type=checkbox id='aaa' name='aaa'>其他选项<input type='text' id='ttt' name='ttt'><br>"
end if
next
%>
<BR>
<input type=button id=b name=b value='检查' onclick="javascript:return chk();">
<SCRIPT LANGUAGE=javascript>
<!--
function chk() {
var c = document.getElementsByName("aaa");
var num=0;
for(var i=0; i < c.length;i++){
if (c[i].checked){
++num;
}
}
if(num==2){
alert("合格");
}
else{
alert("只能选择其中的2个,且必须选2个");
}
}
//-->
</SCRIPT>
<%
for i=0 to 4
Response.Write "<input type=checkbox id='aaa' name='aaa'><br>"
next
%>
<input type=button id=b name=b value='检查' onclick="javascript:void chk();">