[英]validation is not working in simple html form
i have made a small code for html form and trying to validate it with javascript but it is not working and not even giving any error... I am not getting whats the problem behind.... i have seen [javascript simple validation not working? 我已经为html表单制作了一个小代码,并试图用javascript验证它,但它没有工作,甚至没有给出任何错误...我没有得到什么背后的问题....我已经看到[javascript简单验证没有工作?
here is my code.. 这是我的代码..
<!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>
并将method="post"
添加到您的form
标记中。
Change this in formValidate() 在formValidate()中更改此
document.myForm.Name.value == ""
to document.myForm.dob.value == ""
document.myForm.Name.value == ""
to document.myForm.dob.value == ""
document.myForm.EMail.value == "" to document.myForm.email.value == ""
Do not use 不使用
document.write("<b>" + day + "/" + month + "/" + year + "</b>");
It will replace the whole contents of your body 它将取代你身体的全部内容
First of all,in your formValidate(),
首先,在你的
formValidate(),
First if condition is incorrect.Your form does not have a "name" element, it should either be "dob" or "age" or "value". 首先,如果条件不正确。您的表单没有“name”元素,它应该是“dob”或“age”或“value”。
Secondly , in the second if instead of this if( document.myForm.EMail.value == "" )
, it should be if( document.myForm.email.value == "" )
. 其次 ,在第二个if而不是
if( document.myForm.EMail.value == "" )
,它应该是if( document.myForm.email.value == "" )
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.