javascript - raising onkeypress element when input value is null -


i developing chat application user-typing , user-erasing functionality having difficulties in calling function when textarea chat input null( when user erase typed )

  var msg=$("#chat_input").val();  if ((e.which== 8 || e.keycode == 8) && (msg.trim() == "" || msg.length <= 1)) {     // call function    } 

when user type 1 letter , erase function not called , if statement false how can fix

backspacing last character or having new lines or spaces means this.value return false

$('#chat_input').keyup(function(e){     if (e.which == 8 && this.value == false) {      } }); 

jsfiddle demo


value false if space, newline etc, don't need trim()

( msg.length <= 1 ) // = true when second last or last 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -