Submit using Ctrl+Enter or Click the button

Asked

Viewed 51 times

0

Currently I use this code to send my messages.

$('#chatEnvia').click(function() {
   $.post( "inc_chatEnvia.php", { acesso: "ok", msg: $("#chatEscrita").val() });
});

I wonder, how do I stop when pressed together Ctrl+Enter the code to send the messages is executed?

It is important that the Submit, so much with the Ctrl+Enter as with the pressing of the button.

  • If the edition I made does not match what I intended to ask, please reverse it or say that I do.

1 answer

1


I think that’s what you need:

$('#chatEnvia').click(function() {
   $.post( "inc_chatEnvia.php", { acesso: "ok", msg: $("#chatEscrita").val() });
});

$('#chatEscrita').keyup(function (e) {
   if (e.ctrlKey && e.keyCode == 13) {
      $('#chatEnvia').trigger('click');
   }
});
  • Only CTRL+Enter works. Click not.

  • But I think you have to add the two events, the click I was already using and the keyup I passed

  • @James saw that you changed your question, you do not want to use the $.post is that it? Want to use the form Submit in both events?

  • That, the $.post should happen when you click the button #chatEnvia or press CTRL+ENTER.

  • So @Tiago, if you put the two methods don’t work? I’ll edit my answer to see if you understand.

  • Only CTRL+Enter works. Click not.

  • @James see if this is what I edited, if not, I’m probably not understanding what you mean, so I’ll open a chat with you, then it’s easier for us to understand blz?

  • Good morning. Thanks for your help. I tried it today. It worked now ;)

  • 1

    I’m glad you helped, anything I’m up for, hug!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.