验证表单复选框是否选中并输出选中个数.但现在这个script代码不能正常运行,请帮忙指教!
<htlm>
<head>
<script Language="JavaScript">
function form_check(){
var an=new Array("answer1","answer2","answer3","answer4","answer5");
var j=0;
for(var i=0;i<5;i++)
{if (document.form1.an[i].checked) j++;} /如果将an[i]换成answer1,则能正常运行并正常判断.请指教为什么an[i]则不能正常运行,输出an[i]也能循环依次得到数组的值.
{window.alert(j); return (false);}
}
</script>
</head>
<form name="form1" method="post" action="submit_test.asp" onsubmit="return form_check();">
<table width=580 border="0" class="9p">
<tr></tr>
<tr></tr>
<tr></tr>
<tr><td width=98% class=10p> <input type="checkbox" name="answer1" value="1"> </td></tr>
<tr><td width=98% class=10p> <input type="checkbox" name="answer2" value="1"></td></tr>
<tr><td width=98% class=10p> <input type="checkbox" name="answer3" value="1"> </td></tr>
<tr><td width=98% class=10p> <input type="checkbox" name="answer4" value="1"> </td></tr>
<tr><td width=98% class=10p> <input type="checkbox" name="answer5" value="1"> </td></tr>
请指教验证表单复选框问题?