简体   繁体   English

验证两个或多个数字字段的形式

[英]validation of two or more number fields in form

<script language = "Javascript">
  function ValidateForm()
{
    var fname=document.frmSample1.name
    var address=document.frmSample1.address
    var mark1 =document.frmSample1.mark1 
    var mark2 =document.frmSample1.mark2
    var mark3 =document.frmSample1.mark3
    if ((fname.value==null)||(fname.value==""))
        {
           alert("Please Enter username")
           return false
        }
    if ((address.value==null)||(address.value==""))
        {
           alert("Please Enter address")
           return false
        } 
    if ((mark1.value==null)||(mark1.value==""))
        {
           alert("Please Enter mark1")
           return false
        } 
     if ((mark2.value==null)||(mark2.value==""))
        {
           alert("Please Enter mark2")
           return false
        } 
         if ((mark3.value==null)||(mark3.value==""))
        {
           alert("Please Enter mark3")
           return false
        } 
    if ((mark1.value!=null)||(mark1.value!=""))

        {
              if(isNaN(mark1.value))
              {
              alert('please enter correct mark1');
              return false
              }
              else
              return true
        }

    if ((mark2.value!=null)||(mark2.value!=""))

        {
              if(isNaN(mark2.value))
              {
              alert('please enter correct mark2');
              return false
              }
              else
              return true
        }
    if ((mark3.value!=null)||(mark3.value!=""))

        {
              if(isNaN(mark3.value))
              {
              alert('please enter correct mark3');
              return false
              }
              else
              return true
        }
}  
</script>
    </head>
    <body>
    <form method="post" action="" enctype="multipart/form-data" name="frmSample1" onSubmit="return ValidateForm()" >
                  name:<input type="text" name="name" value=""><br><br>
                  address:<input type="text" name="address" value=""><br><br>
                  image:&nbsp;&nbsp;<input type="file" name="file" id="file"><br><br>
                  mark1:<input type="text" name="mark1" value=""><br><br>
                  mark2:<input type="text" name="mark2" value=""><br><br>
                  mark3:<input type="text" name="mark3" value=""><br><br>

                 <input type="submit" name="submit" value="submit">

                </form>

    </body>
</html>

This form contains three marks fields. 此表单包含三个标记字段。 I want to validate whether the three mark fields are entered by the numbers or not.The given code is checking only the first mark is number or not. 我想验证三个标记字段是否由数字输入。给定的代码仅检查第一个标记是否为数字。

This form contains three marks fields. 此表单包含三个标记字段。 I want to validate whether the three mark fields are entered by the numbers or not.The given code is checking only the first mark is number or not. 我想验证三个标记字段是否由数字输入。给定的代码仅检查第一个标记是否为数字。

This form contains three marks fields. 此表单包含三个标记字段。 I want to validate whether the three mark fields are entered by the numbers or not.The given code is checking only the first mark is number or not. 我想验证三个标记字段是否由数字输入。给定的代码仅检查第一个标记是否为数字。

You need to remove the: 您需要删除:

return true

Using return stops execution of the function. 使用return停止执行该功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM