I am unable to stop this form from being submitted (if validation fails).
The form has the onSubmit="return validateThisFrom (this);"
attribute.
<form action="php/create-user.php" method="POST" onSubmit="return validateThisFrom (this);">
The validate function should return false if the passwords are not matched. These are the password fields and their ids.
<input type="password" id="password">
<input type="password" id="confirm_password">
This is the function
function validateThisFrom(thisForm) {
var pwd1 = document.getElementById('password').value;
var pwd2 = document.getElementById('confirm_password').value;
if (thisForm.password.value != thisForm.confirm_password.value) {
document.getElementById('message').style.color = '#dc3545';
document.getElementById('message').style.fontSize = '13px';
document.getElementById('message').innerHTML = '<b>The passwords don\'t match!</b>.';
document.getElementById('password').style.borderColor = '#dc3545';
document.getElementById('confirm_password').style.borderColor = '#dc3545';
document.getElementById('button-addon1').style.borderColor = '#dc3545';
document.getElementById('button-addon2').style.borderColor = '#dc3545';
return false;
}
}
The message The password don't Match
appears but then the form was being submitted even though the function returns false.
As you can see in the photo the message appears but then the form is being submitted.