A simple solution would be something like this
$( "form" ).on( "submit", function() {
var has_empty = false;
$(this).find( 'input[type!="hidden"]' ).each(function () {
if ( ! $(this).val() ) { has_empty = true; return false; }
});
if ( has_empty ) { return false; }
});
Note: The jQuery.on()
method is only available in jQuery version 1.7+, but it is now the preferred method of attaching event handlers.
This code loops through all of the inputs in the form and prevents form submission by returning false if any of them have no value. Note that it doesn't display any kind of message to the user about why the form failed to submit (I would strongly recommend adding one).
Or, you could look at the jQuery validate plugin. It does this and a lot more.
NB: This type of technique should always be used in conjunction with server side validation.