$("#button").bind("click", function () { var messageLenght = $("#text").length(); if($('#text').val() != '' && messageLenght < 200 ){ var message = $("#text").val(); $.ajax({ url: "chatGetMsg.php", type: "POST", data: {message}, dataType: "json", complete: function () { show('send'); del(); } }); } }); 

Why does not it work

 messageLenght < 200 

    1 answer 1

    $("#text") returns a set item. There is no method length() for this object (there is a length property, but it returns the number of elements in the set, that is, 1 for your case). If you need to get the length of the message, this is done using the length property of the String $("#text").val().length object

     $("#button").bind("click", function () { var message = $("#text").val(); var messageLenght = message.length; if(message != '' && messageLenght < 200 ){ $.ajax({ url: "chatGetMsg.php", ...............