JS验证问题,求高手指点,在线等待...急
<HTML>
<HEAD>
<TITLE> test </TITLE>
</HEAD>
<BODY>
<form id= "form1 " name= "form1 " method= "post " action= " ">
数量 <input type= "text " name= "num " /> <br /> <br /> <br />
A <input type= "text " name= "a " value= "0 " /> <br />
B <input type= "text " name= "b " value= "0 " /> <br />
C <input type= "text " name= "c " value= "0 " /> <br />
D <input type= "text " name= "d " value= "0 " /> <br />
E <input type= "text " name= "e " value= "0 " /> <br />
F <input type= "text " name= "f " value= "0 " /> <br />
<input type= "submit " name= "Submit " value= "OK " />
</BODY>
</form>
</HTML>
如上代码,,在提交表单之前,js怎么验证数量里的数值和下面A,B,C,D,E,F中填写的数值符合。
比如我在数量里填写了5,而A,B,C,D,E,F我全部填写了,这样就不对。
数量里写5的话,F的数值肯定是0.也就是说A,B,C,D,E,F中间不允许断开
如果我在数量里写3的话,就一定非要是A,B,C有数值,D,E,F为0.而不允许A有值,B无值(为0),C有值,D有值这样的情况。
A,B,C,D,E,F这6个框的值一定要连续的,允许最后面的为0,前面的中间不允许。如果开头和中间有0值的话则给出提示。
求高手指点JS该如何写。急。在线等待。
能用的分送你了。
------解决方案-------------------- <HTML>
<HEAD>
<TITLE> test </TITLE>
<script language= "javascript ">
function testGG(){
var iNo = 0;
var textName = [ "a ", "b ", "c ", "d ", "e ", "f "];
for(var i = 0;i < textName.length;i++){
var yyy = eval( "document.form1. "+textName[i]+ ".value ");
if(yyy!=0){
iNo++
}else{
break;
}
}
var xxx = document.form1.num.value;
alert(iNo);
if(xxx != iNo){
alert( "error ");
return;
}else{
form1.submit();
}
}
</script>
</HEAD>
<BODY>
<form id= "form1 " name= "form1 " method= "post " action= " ">
数量 <input type= "text " name= "num " /> <br /> <br /> <br />
A <input type= "text " name= "a " value= "0 " /> <br />
B <input type= "text " name= "b " value= "0 " /> <br />
C <input type= "text " name= "c " value= "0 " /> <br />
D <input type= "text " name= "d " value= "0 " /> <br />
E <input type= "text " name= "e " value= "0 " /> <br />
F <input type= "text " name= "f " value= "0 " /> <br />
<input type= "bu