javascript - Jquery textarea.val('') adds line break on FIRST enter press? -
i have little chat setup, , on enter press if text area in focus have set submit chat database , clear text area. unfortunately though, first time 1 presses enter adds linebreak in text area, in browser. if type , press enter again, there's still 1 line break there. missing something?
thanks!
$(document).keypress(function(keypress) { if (keypress.which == 13) { if ($('#chattext').is(':focus')) { if ($('#chattext').val().length > 0) { chatvalue = $('#chattext').val(); $('#chattext').val($('#chattext').val().substring(0,0)); $.ajax({ type: 'post', url: 'submitchat.php', data: { chattext: chatvalue }, success: function(result) { $('#chat_text').html(result); document.getelementbyid('chat_text').scrolltop = 9999999; } }); } } } });
why don't clear it?
$('#chattext').keypress(function(e) { if (e.which == 13) { var value = $(this).val(); if (value.length > 0) { $(this).val(''); $.ajax({ type: 'post', url: 'submitchat.php', data: { chattext: value }, success: function(result) { $('#chat_text').html(result); this.scrolltop = 9999999; } }); } } });
Comments
Post a Comment