I have a form to insert user to a database. On the other side I have two scripts of password validation and ajax script which retrieve php result.
Right now the two script are working separately.
What should I do so that the ajax script run after the password validation?
Password Validation
function Validate() {
var password = document.getElementById("UserPwd").value;
var confirmPassword = document.getElementById("ConfirmUserPwd").value;
if (password != confirmPassword) {
alert("Please enter the same password");
return false;
}
return true;
}
Script
$.ajax({
url: "insert_sp.php",
method: "POST",
data: {submit: 'true'},
success: function(response) {
var data = JSON && JSON.parse(response) || $.parseJSON(response);
alert(data);
}
});
Update
isset : if(isset($_POST['Submit']))
button : <input type="submit" name="Submit" value="Submit"/>
$(function() {
$("#myForm").on("sumbit", function(e) {
e.preventDefault();
var password = $("#UserPwd").val(),
confirmPassword = $("#ConfirmPassword").val();
if ($.trim(password) === password &&
password !== "" &&
password === confirmPassword) {
$.ajax({
url: "insert_sp.php",
method: "POST",
data: {
submit: 'true'
},
success: function(response) {
var data = JSON && JSON.parse(response) || $.parseJSON(response);
alert(data);
}
});
}
else {
alert("Please enter the same password");
}
});
});