Hi guys,
This is really bugging me - if I use .click instead of .submit, the code works as intended.
At the moment .submit doesn’t bother executing any of the script, the form just submits.
$(document).ready(function($) {
$('#sendform').submit(function(event) {
if ($('input:text').val().length > 0) {
// validate if at least one form field is populated
alert("Well done, at least one form field is populated!");
event.preventDefault();
}
else {
// all form fields empty, don't submit
alert("All form fields empty!");
event.preventDefault();
}
});
});
The HTML:
...form fields...
<input type="submit" id="sendform" value="Submit" />
I’ve been bouncing between sites and cannot see an issue with why this wouldn’t work. Please help!!