Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trim and check if empty input

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?

like image 987
Jürgen Paul Avatar asked Jan 06 '12 09:01

Jürgen Paul


2 Answers

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

like image 199
Manse Avatar answered Sep 21 '22 00:09

Manse


if($.trim($('.xlarge').val()) == "") {
    return false;
}
like image 26
stamp Avatar answered Sep 21 '22 00:09

stamp