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
  • 115,559
  • 50
  • 294
  • 378
Simon Thomsen
  • 1,321
  • 7
  • 27
  • 36

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,853
  • 3
  • 26
  • 46