if statement - onsubmit: jQuery alert if field is empty -
on website, have button says "get free consultation" , next button email field. when user types in email , presses button, email submitted google spreadsheet, , popup appears more information.
how can add jquery code "onsubmit" part of tag says: if email field contains email address, submit form , show popup. otherwise ("else"), display alert box says "please enter email address."
here's code looks 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 free 
 consultation" class="landing-pg-button">
thanks in advance!
try
jquery(function($){ var $form = $('#ss-form-landing'), $field = $form.find('input.landing-pg-email-field'); $form.submit(function(){ if($.trim($field.val()) == ''){ alert('enter email id'); return false; } }) })
demo: fiddle
Comments
Post a Comment