I am trying to validate the billing email and phone number inputs on this page using a script that is already in place on the site:
I have tried all sorts of variations, and can't get it to work. Clicking submit with the email and phone fields empty triggers the "email required" message as intended. However, putting an email address into the field doesn't stop the message from appearing, and the form won't submit. Can anyone see what I'm doing wrong?
The problem with your script is this line:
if (document.getElementsByName('BillEmail').value == null)
which in your case is always undefined, regardless of whether you enter a value.
This is because
document.getElementsByName will return a collection of HTML elements.
As you want to access the first element, change your code to:
if (document.getElementsByName('BillEmail').value == '')
and you'll be good to go.
Oh, and you'll have to do the same for BillPhone, too.
Oh thank you, and thank you for taking the time to explain it in such a clear way. It makes perfect sense now that I see what it's doing. Better yet, it's working! Much appreciated
This topic is now closed. New replies are no longer allowed.