tinyqueen — 2012-12-20T13:09:10-05:00 — #1
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?
pullo — 2012-12-21T13:34:45-05:00 — #2
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.
tinyqueen — 2012-12-21T16:17:48-05:00 — #3
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
pullo — 2012-12-21T16:21:40-05:00 — #4