When ever I try submitting the form I either get an error, or if I type it manually in my console I get this error:
RangeError: Maximum call stack size exceeded
Here's my code:
$(document).ready(function() {
$('#contact').on('submit', function(event) {
event.preventDefault();
var valid = 1;
var name = $('input[name$="name"]');
var email = $('input[name$="email"]')
var phone = $('input[name$="phone"]');
var comment = $('input[name$="comment"]');
if (!name.val() && valid == 1) {
valid = 0;
alert('Please fill out the Name field');
name.focus();
}
if (!email.val() && valid == 1) {
valid = 0;
alert('Please fill out the E-mail Address field');
email.focus();
}
if (!phone.val() && valid == 1) {
valid = 0;
alert('Please fill out the Phone field');
phone.focus();
}
if (valid == 1) {
$('#contact').submit();
}
})
});
You're calling submit from the submit handler, so it's infinite recursion. You want to return true
if valid and false
otherwise.
Edit: Oh, and I'm not sure you want to preventDefault in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With