Ok, well let’s make something that you can drop in the page and have work.
You currently have everything happening in the onsubmit
action on your button:
<input type="button" name="btnSubmit" value="Continue" onclick="(function(){if(document.forms[0]['txtPassword'].value != document.forms[0]['txtPasswordVerify'].value){alert('Please make sure passwords match!'); document.forms[0]['txtPasswordVerify'].value=''; document.forms[0]['txtPassword'].value=''; document.forms[0]['txtPasswordVerify'].style.borderColor='red'; document.forms[0]['txtPassword'].style.borderColor='red';}else{document.forms[0].submit();}})()" />
We can simplify that to this:
<input
type="button"
name="btnSubmit"
value="Continue"
onclick="<code to check that passwords match>"
/>
The code to make sure the passwords match can be expanded to this:
(function(){
if(document.forms[0]['txtPassword'].value != document.forms[0]['txtPasswordVerify'].value){
alert('Please make sure passwords match!');
document.forms[0]['txtPasswordVerify'].value='';
document.forms[0]['txtPassword'].value='';
document.forms[0]['txtPasswordVerify'].style.borderColor='red';
document.forms[0]['txtPassword'].style.borderColor='red';
} else {
document.forms[0].submit();
}
})()
That works, but we will need to change the logic somewhat like so:
(function(){
if (passwords don't match){
alert('Please make sure passwords match!');
...
}
if (emails don't match) {
alert('Please make sure emails match!');
...
}
Otherwise submit the form
})()
In code you could do it like this:
(function(){
var isValid = true;
if (document.forms[0]['txtPassword'].value != document.forms[0]['txtPasswordVerify'].value) {
alert('Please make sure passwords match!');
document.forms[0]['txtPasswordVerify'].value='';
document.forms[0]['txtPassword'].value='';
document.forms[0]['txtPasswordVerify'].style.borderColor='red';
document.forms[0]['txtPassword'].style.borderColor='red';
isValid = false;
}
if (document.forms[0]['txtEmail'].value != document.forms[0]['txtEmailVerify'].value) {
alert('Please make sure email addresses match!');
document.forms[0]['txtEmail'].style.borderColor='red';
document.forms[0]['txtEmailVerify'].style.borderColor='red';
isValid = false;
}
if (isValid) document.forms[0].submit();
})();
Note that I am not resetting the value in the email fields if the values don’t match (as is happening in the password fields).
Then the final thing to do it to remove the spaces and stick it in a string:
Giving you:
<input type="button" name="btnSubmit" value="Continue" onclick="(function(){var isValid = true;if (document.forms[0]['txtPassword'].value != document.forms[0]['txtPasswordVerify'].value){alert('Please make sure passwords match!');document.forms[0]['txtPasswordVerify'].value='';document.forms[0]['txtPassword'].value='';document.forms[0]['txtPasswordVerify'].style.borderColor='red';document.forms[0]['txtPassword'].style.borderColor='red';isValid = false;}if (document.forms[0]['txtEmail'].value != document.forms[0]['txtEmailVerify'].value) {alert('Please make sure email addresses match!');document.forms[0]['txtEmail'].style.borderColor='red';document.forms[0]['txtEmailVerify'].style.borderColor='red';isValid = false;}if(isValid){document.forms[0].submit();}})();" />
Try that and let me know if it works