Wednesday, 7 August 2013

onsubmit: jQuery alert if field is empty

onsubmit: jQuery alert if field is empty

On my website, I have a button that says "GET A FREE CONSULTATION" and
next to the button is an email field. When the user types in their email
and then presses the button, their email is submitted to a google
spreadsheet, and a popup appears with more information.
How can I add jQuery code into the "onsubmit" part of the tag that says:
If the email field contains an email address, submit the form and show the
popup. Otherwise ("else"), display an alert box that says "Please enter
your email address."
Here's what my code looks like now:
<form action="https://docs.google.com/forms/d/xxxxx/formResponse"
method="POST" id="ss-form-landing"
onsubmit="$('.landing-button').click();return true;"
target="hidden_iframe">
<input type="text" name="entry.xxx" value="" id="entry_2005747986"
class="landing-pg-email-field" placeholder="Enter email address"><input
type="submit" name="submit" value="GET A FREE &#x00A; CONSULTATION"
class="landing-pg-button">
Thanks in advance!

No comments:

Post a Comment