Question

Here is a Bin = http://jsbin.com/ekasuv/1/edit

code I am using is this:

  $('#pop_up').on('keyup','.textual',function(event){
          var did= $(this).attr('data-id');
      if(did ==="titles_sendto"){
          var keycode = (event.keyCode ? event.keyCode : event.which);   
      if(keycode === '13') {
          var AuthSendUser = $(this).val();
       $('#ListedAuthSend').append('<li>'+ AuthSendUser +'</li>');
       $(this).val(" ");
     }
   }
});

Though everytime I press enter it does not pass the code. Now maybe I am overlooking something or just forgetting something. though I am tired, and need some of S.O assistance. Can someone take a glance and see what I may be doing wrong.

I've also tried .on('focus',

Was it helpful?

Solution

$('#pop_up').on('keyup','.textual',function(e){
   var did= $(this).attr('data-id');
   if(did == "titles_sendto" && e.which == 13){
       $('#ListedAuthSend').append('<li>'+ this.value +'</li>');
       this.value = '';
   }
});

BIN

OTHER TIPS

If I understood you correctly, your code doesn't pass the if statement when you press enter? This works for me:

if(keycode == '13'){
  alert('passed');
}

just use two = sign and it works fine. Here's your edited JSBIN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top