Reputation: 15037
if(!$.trim($('.xlarge').value).length) {
return false;
}
And the HTML is:
<input class="xlarge" name="name">
I checked on my console if the syntax is right, it is right, but even if the value is not empty it still doesn't submit the form. What's wrong?
Upvotes: 7
Views: 14358
Reputation: 38147
No need to check length just use :
if(!$.trim($('.xlarge').val())) {
return false;
}
val() returns the value of the input - docs for val()
Discussed here Check if inputs are empty using jQuery
Upvotes: 7
Reputation: 15062
Instead of:
$('.xlarge').value
You should use:
$('.xlarge').val()
.val()
is the jQuery function which will return the value
of the first element in the set of matched elements. Here's a link to the documentation: http://api.jquery.com/val/.
Upvotes: 2