1

I'm creating a facebook application at the moment and need to create a comment system. I've made the most of it, but the only thing i not have made yet is the textarea sending progress.

I want to make it like facebook have done it with the comment system on facebook.

So when a user clicks enter, then a ajax request happens, but if a user press shift+enter, the user makes a linebreak without any ajax request to my server.

Kev
  • 118,037
  • 53
  • 300
  • 385
Simon Thomsen
  • 1,351
  • 7
  • 27
  • 37

1 Answers1

1

Try this :

$('#target').keypress(function(event) {
  if (event.which == '13' && !event.shiftKey) {
     // Yout ajax request here
   }
});

The corresponding doc is here : http://api.jquery.com/keypress/

EDIT : According to this question, the following is better :

$('#target').keypress(function(event) {
    if (((event.keyCode || event.which) == 13) && !event.shiftKey) {
        // Yout ajax request here
    }
});
Community
  • 1
  • 1
Romain Guidoux
  • 2,943
  • 4
  • 28
  • 48