The following javascript works by comparing two inputs “name” value for “required_email” and “verify_email” before submitting. The problem is the “names” are actually “required-email” and “verify-email”. It appears dashes aren’t support in the name’s in javascript. Clearly the easiest solution would be to use an underscore or no space but that is not possible because the server side form processing looks for particular “names” that use the dashes.
I can add an ID to each of the two inputs, so all I need to know is how to modify the following javascript to compare #input1 with #input2 (aka use the ID’s rather than the name values).
function checkEmail(theForm) {
if (theForm.required_email.value != theForm.verify_email.value)
{
alert('Your emails don\'t match.');
return false;
} else {
return true;
}
}
PS. I need this done in plain javascript (not jQuery or other frameworks).
1 Answer