I'm using the following code to send some value from a textarea but first i want to ensure that the Textarea is not empty and then if not empty on keypress "Enter" then send the value to ajax.
The problem is value length counts line breaks and the validation fails. Another is line breaks, How do i prevent line breaks?
JAVASCRIPT
$(document).keypress(function(e) {
if(e.which == 13) {
if ($('.msgInput').val().length < 2){
alert ('No lol, your message is too short, type some more...')
} else {
var Msg = $('#Messageinput').val()
$.ajax({
type:"POST",
data: {
data:Msg
},
url:"../websocket-example-821156/client.php"
}).done(function(feedback){
$('#NewMessagesHolder').prepend('<div class="MessageClass ServerMessage">'+ '<span class="ChatName">Server ('+ time + ')</span>' + ':'+feedback+'</div>');
})
var text = $('.msgInput').val();
$('.msgInput').val("");
$('#NewMessagesHolder').prepend('<div class="MessageClass">'+ '<span class="ChatName">' + CookieName + ' ('+ time + ')</span>' + ': '+ text +'</div>')
}
}
});
var Msg = $.trim($('#Messageinput').val()); if(e.which == 13) { if (Msg.length < 2){ alert ('No lol, your message is too short, type some more...') } else {
... - mplungjan