简体   繁体   English

表单onSubmit不调用javascript函数

[英]form onSubmit doesn't call javascript function

I have checked recent blogs about onsubmit event not triggering the method. 我查看了最近关于onsubmit事件的博客没有触发该方法。 Those suggestions were not helpful for this problem.And i've tried this method and form in an another html page which didn't work either.So i am not able to find out where main problem is ? 这些建议对这个问题没有帮助。我已经尝试了这个方法并在另一个html页面中形成了不起作用。所以我无法找出主要问题在哪里? My code : 我的代码:

<div id="_div2">
<center>
<div class="contianer">

<script type="text/javascript">
function formValidation ()
{
    var fName =document.Log.firstName.value;
    var lName =document.Log.lastName.value;
    var pName =document.Log.penName.value;
    var email =document.Log.email.value;
    var password=document.Log.password.value;
    var confirmPassword=document.Log.confirmPassword.value;
    var status=false;
    if(fName.length<1)
    {
        document.getElementById("firstNameLoc").innerHTML=
        "<img src='Resource/unchecked.gif'/>Please Enter your First Name";
        status=false;
    }
    else 
    {
        document.getElementById("firstNameLoc").innerHTML=
        "<img src="Resource/checked.png"/>Please Enter your First Name";
        status=true;
    }
    return status;
}
</script>


<form name="Log" action="SignUpInsert.php" method="post" onsubmit="return formValidation();return false;">
<label><b>First Name</b></label><span id="firstNameLoc"></span><br>
<input type="text" placeholder="Enter your Last Name"  name="firstName"><br>
<label><b>Last Name</b></label><span id="lastNameLoc"></span><br>
<input type="text" placeholder="Enter your Last Name" name="lastName"><br>
<label><b>Pen Name</b></label><span id="penNameLoc"></span><br>
<input type="text" placeholder="Enter your Unique Pen Name" name="penName"><br>
<label><b>Email</b></label><span id="emailLoc"></span><br>
<input type="text" placeholder="Enter your Email" name="email"><br>
<label><b>Password</b></label><span id="passwordLoc"></span><br>
<input type="password" placeholder="Enter your Password" name="password"><br>
<label><b>Confirm Password</b></label><span id="confirmPasswordLoc"></span><br>
<input type="password" placeholder="Enter your Password Again" name="confirmPassword"><br>
<input type="submit" title="Done?" value="Sign Up"><br>

<div class ="contianer">
<button type="button" class="cancelBtn" title="Go Back" onclick="location.href='Main.html'">Cancel</button>
</div>

</form>
</div>
</center>

you almost done. 你几乎完成了。 simple quotes problem.you could change like this in your dom else statement 简单的quotes问题。你可以在你的dom else语句中改变这个

document.getElementById("firstNameLoc").innerHTML = '<img src="Resource/checked.png"/>Please Enter your First Name';

 function formValidation() { var fName = document.Log.firstName.value; var lName = document.Log.lastName.value; var pName = document.Log.penName.value; var email = document.Log.email.value; var password = document.Log.password.value; var confirmPassword = document.Log.confirmPassword.value; var status = false; if (fName.length < 1) { document.getElementById("firstNameLoc").innerHTML = "<img src='Resource/unchecked.gif'/>Please Enter your First Name"; status = false; } else { document.getElementById("firstNameLoc").innerHTML = '<img src="Resource/checked.png"/>Done..!'; status = true; } return status; } 
 <div id="_div2"> <center> <div class="contianer"> <form name="Log" action="SignUpInsert.php" method="post" onsubmit="return formValidation();return false;"> <label><b>First Name</b></label><span id="firstNameLoc"></span><br> <input type="text" placeholder="Enter your Last Name" name="firstName"><br> <label><b>Last Name</b></label><span id="lastNameLoc"></span><br> <input type="text" placeholder="Enter your Last Name" name="lastName"><br> <label><b>Pen Name</b></label><span id="penNameLoc"></span><br> <input type="text" placeholder="Enter your Unique Pen Name" name="penName"><br> <label><b>Email</b></label><span id="emailLoc"></span><br> <input type="text" placeholder="Enter your Email" name="email"><br> <label><b>Password</b></label><span id="passwordLoc"></span><br> <input type="password" placeholder="Enter your Password" name="password"><br> <label><b>Confirm Password</b></label><span id="confirmPasswordLoc"></span><br> <input type="password" placeholder="Enter your Password Again" name="confirmPassword"><br> <input type="submit" title="Done?" value="Sign Up"><br> <div class="contianer"> <button type="button" class="cancelBtn" title="Go Back" onclick="location.href='Main.html'">Cancel</button> </div> </form> </div> </center> 

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

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