I am hoping that someone is much better at javascript than I am, and can help me. I need to compare 2 different sets of email addresses on a form. For each pair, if they do not match, I need an error message to display, and for the user to not be able to submit the form. I found code on an old post that shows how to do this for one set of email addresses.
$(document).ready(function () { $('.email, .confirm').on('blur input', function () { if ($('.email input').val() != $('.confirm input').val()) { $('.Submit').hide(); if ($('.warningText').length > 0 || $('.confirm input').val() == '') { return; } else { $('<p class="warningText"><font color="red">The email addresses you entered do not match.</p>').insertAfter('.confirm'); } } else $('.warningText').remove(); }) });
I tried modifying it to use with 2 sets of email addresses as such:
$(document).ready(function () {
$('.email, .confirm, .email2, .confirm2').on('blur input', function () {
if ($('.email input').val() != $('.confirm input').val()) {
$('.Submit').hide();
if ($('.warningText').length > 0 || $('.confirm input').val() == '') { return; }
else {
$('<p class="warningText"><font color="red">The email addresses you entered do not match.</p>').insertAfter('.confirm');
}
}
if ($('.email2 input').val() != $('.confirm2 input').val()) {
$('.Submit').hide();
if ($('.warningText2').length > 0 || $('.confirm2 input').val() == '') { return; }
else {
$('<p class="warningText2"><font color="red">The email addresses you entered do not match.</p>').insertAfter('.confirm2');
}
}
else
$('.warningText2').remove();
$('.warningText').remove();
$('.Submit').show();
})
})
Unfortunately, it only shows the error on the first pair after all 4 entries are filled in. Also, it won't show an error on the second pair, unless the first pair matches. Plus, when the first set is good the Submit button shows even if the second pair doesn't match.
I would appreciate any help that I can get on this.