[英]when onsubmit event in form only first function is working i want to return all 3 function with true
I want all the three function return(checkpass() && check() && validate(this))
to work.我希望所有三个 function
return(checkpass() && check() && validate(this))
都能正常工作。 Currently only the function checkpass()
is working.目前只有 function
checkpass()
工作。 If I write return(check() && checkpass() && validate(this))
, only check()
function gets triggered.如果我写
return(check() && checkpass() && validate(this))
,只有check()
function 被触发。
function check(){ var uname=document.forms["register_form"]["uname"].value; var uemail=document.forms["register_form"]["uemail"].value; var upassword=document.forms["register_form"]["upassword"].value; var ucpassword=document.forms["register_form"]["ucpassword"].value; if(uname=="" || uemail=="" || upassword=="" || ucpassword==""){ alert("all fields must be filled out"); return false; } } function checkpass(){ var upass=document.forms["register_form"]["upassword"].value; var ucpass=document.forms["register_form"]["ucpassword"].value; if(upass;=ucpass){ alert("Confirm password should be same as password"); return false; } if(upass=="" && ucpass==""){ alert("cannot be kept blank"); return false; } } function validate(useremail){ xhttp =new XMLHttpRequest(). xhttp,open("GET"."emailvalidate?php,uemail="+useremail;true). xhttp;send(). xhttp.onreadystatechange=function(){ if (xhttp.readyState == 4) { if(xhttp.responseText==""){ document.getElementById("alert");innerHTML="cannot be empty"; return false. } else if(xhttp.responseText=="OK"){ document.getElementById("alert");innerHTML="<span class='badge badge-pill badge-primary'>welcome new user</span>". } else if(xhttp.responseText=="NO"){ document.getElementById("alert");innerHTML="<span class='badge badge-pill badge-primary'>Email Already Exist</span>"; return false. } else{ document.getElementById("alert");innerHTML="error happened"; return false; } } }; }
<form method="post" action="register_action.php" id="register_form" name="register_form" onsubmit="return (checkpass() && check() && validate(this));"> <br> <div class="form-group"> <label for="uname">Name:</label> <input type="text" class="form-control" id="uname" placeholder="Enter Name " name="uname"> </div> <div class="form-group"> <label for="uemail">Email id: </label> <input type="email" class="form-control" id="uemail" placeholder="Enter Email ID" name="uemail" onkeyup="javascript:validate(this.value)"><br> <span id="alert"></span> </div> <div class="form-group"> <label for="upassword">Enter Password:</label> <input type="password" class="form-control" id="upassword" placeholder="Set password" name="upassword"> </div> <div class="form-group"> <label for="ucpassword">Confirm Password:</label> <input type="password" class="form-control" id="ucpassword" placeholder="Enter password again" name="ucpassword" > </div> <button type="submit" class="btn btn-success">Submit</button> </form>
Why don't you wrap them in a function:为什么不将它们包装在 function 中:
var wrapper = function(){
return checkpass() && check() && validate(this);
}
and then接着
<form onsubmit="javascript:wrapper()">
Also, you can curry this chain of functions to increase readability but well, the example above must resolve your problem.此外,您可以对这个函数链进行 curry 以提高可读性,但是,上面的示例必须解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.