I c...">

Trim and check if input is empty

if(!$.trim($('.xlarge').value).length) { return false; } 

And HTML:

 <input class="xlarge" name="name"> 

I checked on my console if the syntax is right, this is correct, but even if the value is not empty, it still does not submit the form. What's wrong?

+6
source share
3 answers

No need to check the length, just use:

 if(!$.trim($('.xlarge').val())) { return false; } 

val () returns the input value - docs for val ()

Discussed here. Check for empty entries using jQuery.

+5
source
 if($.trim($('.xlarge').val()) == "") { return false; } 
+3
source

Instead:

 $('.xlarge').value 

You should use:

 $('.xlarge').val() 

.val() is a jQuery function that will return the value first element in the set of matched elements. Here's a link to the documentation: http://api.jquery.com/val/ .

+2
source

Source: https://habr.com/ru/post/905290/


All Articles