-2
我有這個HTML與JavaScript驗證窗體,但我不知道爲什麼它不工作。它現在應該按下按鈕時計算兩個文本框的值。然而沒有發生。代碼:HTML javascript valIdation不工作
<html>
<head>
<title>Form Validator</title>
<script type="text/javascript">
//script here
function Validate()
{
var numbers = /^[0-9]+$/;
var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname = document.myform.FullName.value,
fmobile = document.myform.Mobile.value,
femail = document.myform.Email.value,
fpass1 = document.myform.pass1.value,
fpass2 = document.myform.pass2.value,
faddress = document.myform.Address.value;
if(fname == "")
{
document.myform.FullName.focus() ;
document.getElementById("errorBox").innerHTML = "enter the name";
return false;
}
if (fmobile == "")
{
document.myform.Mobile.focus();
document.getElementById("errorBox").innerHTML = "enter the Mobile Number";
return false;
}else if(!numbers.test(fmobile)){
document.myform.Mobile.focus();
document.getElementById("errorBox").innerHTML = "enter the valid Mobile number";
return false;
}
if (femail == "")
{
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the email";
return false;
}else if(!emailRegex.test(femail)){
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the valid email";
return false;
}
if (fpass1 == "")
{
document.myform.pass1.focus();
document.getElementById("errorBox").innerHTML = "enter the Password";
return false;
}else if(fpass1.length > 8){
document.myform.pass1.focus();
document.getElementById("errorBox").innerHTML = "Password must be greater than 8 length";
return false;
}
if (fpass2 == "")
{
document.myform.pass2.focus();
document.getElementById("errorBox").innerHTML = "enter the Confirm Password";
return false;
}
if(fpass1 != fpass2){
document.myform.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "Passwords are not matching, re-enter again";
return false;
}
if (faddress == "")
{
document.myform.Address.focus();
document.getElementById("errorBox").innerHTML = "enter the Address";
return false;
}
if(fname != '' && fmobile != '' && femail != '' && fpass1 != '' && fpass2 != '' && faddress != ''){
document.getElementById("errorBox").innerHTML = "form submitted successfully";
}
}
</script>// script ends here
</head>
<body>
<form action="" name="myform" method="post" onsubmit="return Validate()" style="text-align:-moz-center;">
// my html simple form start from here
<table cellspacing="2" cellpadding="2" border="0" >
<tr>
<td align="right">Full Name</td>
<td><input type="text" name="FullName"></td>
</tr>
<tr>
<td align="right">Mobile</td>
<td><input type="text" name="Mobile"></td>
</tr>
<tr>
<td align="right">Email</td>
<td><input type="text" name="Email"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="text" name="pass1"></td>
</tr>
<tr>
<td align="right">Confirm Password</td>
<td><input type="text" name="pass2"></td>
</tr>
<tr>
<td align="right">Address</td>
<td><textarea cols="20" rows="5" name="Address"></textarea></td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" value="Submit" "> <div id="errorBox"></div></td>
</tr>
</table>
</form>
</body>
</html>
你是一個調試器? – nicael
這是他的問題的答案。該按鈕沒有工作,因爲他錯過了關閉一個字符串... –
好的,但這樣的問題不應該回答。標記他們。 OP應該學會使用調試器。 – nicael