JQuery is not an error function

What is wrong with this statement?

message = $("#contact-form").find(".long-text");

if(message.val().length < 15)
{
    message.css("border","2px solid red");
    alert("Your message must be more than 15 character long");
}

I get message.val is not an error function in Firebug ? What could be the reason?

NEW

OK, now my form will not be submitted if I have more or less 15 characters. Should I open a new question on this issue or should it continue?

I have this inside:

$("#contact-form").submit(function(){
  message = $("#contact-form").find(".long-text");

    if(message.val().length < 15)
    {
        message.css("border","2px solid red");
        alert("Your message must be more than 15 character long");
        return false;
    }
    else {
        Post form with Ajax ..
    }
});
+3
source share
4 answers

As you can see in the highlighter syntax, the quotes went fictitious :) There is no double comment.

, val() input (input, select, textarea button). input, text(). , , length(), , , length.

jQuery tutorials / , jQuery book.

+5

, ,

  • length - , . message.val().length
  • val() HTML. message.html().length text(), .
0

.length length()

0

message = $("#contact-form").find(".long-text").first();
-1

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


All Articles