.submit() not working

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!! :slight_smile:

I really don’t know what you’re trying to do, but the submit method isn’t the same as a click method. I also don’t understand if you say the code is working with the click method why bother changing it?

I am taking a guess that you want to do something like the following:

[php]

Untitled Document

Welcome to the Pleasuredome!





[/php]

The code is a little messy and definitely needs to be refined.

Sponsor our Newsletter | Privacy Policy | Terms of Service