I have a textArea where you type a message, and to submit it you have to press a button.
The whole submitting process will be in JS/jQuery. For now the submission will be triggered only by the onclick event of the submit button.
$(".btn-success").click(function () {
// Submit Code
});
Now I want to combine :
$('textarea').keypress(function (e) {
if(e.which == 13) {
// Same Submit Code
}
});
So that when the user presses ‘enter’, the message is submited, without having to repeat the function twice.
Any help ? Couldn’t find anything on the forum…
3
Answers
the function was born to do it give it a name:
Simply use a standard named function:
if the functions were exactly the same end the events occure on same element I was going to recommend joining them with
on
:Yet, as this is not the case, The Simple Answer is Creating a submit function and calling it in the different events callbacks