I have a bit of jquery that is submitting a email sign up form for me. Everything works fine when the user clicks the button, but when the hit enter it seems the form is trying to submit through the html not through the jquery and you get taken to where the form should post. I have tried using .submit instead of .click but that didnt seem to work
$('#email-signup-button').click(function () {
var email = $('#email-address').val();
// Check to see if field is blank
if (email.length < 1) {
errorLog += ('Please provide an email address.');
errorCount++;
}
// If field is email address, check w/ regex
if (email.match(emailRegex) == null) {
if (errorCount == 0) {
errorLog += ('Email address is invalid.\nPlease verify.');
errorCount++;
}
}
if (errorCount > 0) {
alert(errorLog);
errorCount = 0;
errorLog = "";
}
else {
$.post("/Home/AddEmail", { emailAddress: email });
alert('Thank you for signing up!');
$('#email-address').val("");
$('#email-signup').hide();
$('.lb_overlay').hide();
}
return false;
});
}
<div id="email-signup">
<h2>
Content Phrase
</h2>
<div class="email-deals-close-button">
</div>
<p>
More Content</p>
<form action="/Home/AddEmail" class="clearfix" method="post">
<p class="sign-up">
<label class="placeholder" for="email-address">
some@email.com</label>
<input type="text" id="email-address" name="email-address" value="" />
</p>
<button id="email-signup-button" type="button" class="green-action-button">
Submit</button>
</form>
</div>