I need to redirect to thank you page after the valid submit a form, my form show the thank you page in both conditions, valid and invalid.
Can anyone help me with this?
$(document).ready(function() {
// Attach the event handler for the keyboard keyup
$('.my-input').keyup(function() {
$(".error").hide();
var hasError = false;
var nameReg = /^([a-zA-Z_ ]{0,50})$/g;
var nameaddressVal = $(".my-input").val()
if (nameaddressVal == "") {
$(".my-input").after(
'<span class="error text-danger">Please enter your name.</span>'
);
hasError = true;
} else if (!nameReg.test(nameaddressVal)) {
$(".my-input").after(
'<span class="error text-danger">Allowed: aA</span>'
);
hasError = true;
}
$('input[type=submit]').click(function() {
if (hasError == true) {
return false;
} else if (nameReg.test(nameaddressVal)) {
window.location.replace("thank_you.php");
}
else{
return false;
}
});
});
});