1

我已经为 html 表单编写了一个小代码,并尝试使用 javascript 对其进行验证,但它无法正常工作,甚至没有给出任何错误......我没有得到背后的问题......我已经看到 [javascript 简单验证不是在职的?

这是我的代码..

  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A simple Input Form</title>
<script type="text/javascript">

function validateEmail() {
    //var emailID = document.myForm.email.value;
    if(!validateNonEmpty(inputField, helpText))
        return false;
    return validateRegEx(/^\d{2}\/\d{2}\/\d{4}$/, inputField.value, helpText, 
            "please enter an email address i.e. johndoe@acme.com");
    }
function validatedob(inputField, helpText){
    if(!validateNonEmpty(inputField, helpText))
        return false;
    return validateRegEx(/^\d{2}\/\d{2}\/\d{4}$/, inputField.value, helpText, 
            "please enter an email address i.e. johndoe@acme.com");
}
function age(){
    var currentDate = new Date()
    var day = currentDate.getDay()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()

}
function formValidate(){
     if( document.myForm.dob.value == "" )
       {
         alert( "Please provide your date of birth!" );
         document.myForm.dob.focus() ;
         return false;
       }
     else {
         var dateformat = validatedate();
         if (dateformat == false)
             {
                return false;
             }
     }
       if( document.myForm.email.value == "" )
       {
         alert( "Please provide your Email!" );
         document.myForm.email.focus() ;
         return false;
       }else{
         var ret = validateEmail();
         if( ret == false )
         {
              return false;
         }
       }
       if (document.myForm.age.value="")
           {
            alert("please provide your age");
            document.myForm.age.focus();
            return false;
           }
       else
           {
       var ageformat = validateage();
       if (ageformat == false)
           {
            return false;
           }
           }
}

</script>
</head>
<body>
<div id="left">
<input type="button" value="previous">
<img src="/images/jump2" alt="Just-in-time" />
</div>
<input type="button" value="next">
    <form name="myForm" method="post" action="success.html" onsubmit="formValidate();">
         Date of Birth: <input id="dob" type="text" name="dob" size=10><br>
         Age: <input id="age" type="text" name="age"><br>
         Email: <input id="email" type="text" name="email"><br>
         <input type="submit" value="Submit">
    </form>
</body>
</html>
4

3 回答 3

2

并添加method="post"到您的form标签中。

于 2013-09-13T10:26:00.383 回答
1

首先,在你的formValidate(),

首先如果条件不正确。您的表单没有“name”元素,它应该是“dob”或“age”或“value”。

其次,在第二个如果不是这个 if( document.myForm.EMail.value == "" ),应该是if( document.myForm.email.value == "" )

于 2013-09-13T10:28:01.120 回答
1

在 formValidate() 中更改它

document.myForm.Name.value == ""document.myForm.dob.value == ""

document.myForm.EMail.value == "" to document.myForm.email.value == ""

不使用

 document.write("<b>" + day + "/" + month + "/" + year + "</b>");

它将取代你身体的全部内容

于 2013-09-13T10:21:06.823 回答