The following code will submit an ajax form when the user hits ctrl+enter while in the feedback input area. It works fine - but only once. I need to bind this function to the comment form so it persists and allows multiple submissions. In other words - the form is cleared and represented to the user after each submission. However, the following code only works for the first submission and thus ctrl+enter doesn't work for the second submission.
$('#comment_body').keydown(function(e) {
if (e.ctrlKey && e.keyCode === 13) {
return $('#comment_submit').trigger('submit');
}
});
I've tried .live and .bind but can't get the syntax right to allow resubmission.
Thanks
We can submit a form by ajax using submit button and by mentioning the values of the following parameters. type: It is used to specify the type of request. url: It is used to specify the URL to send the request to. data: It is used to specify data to be sent to the server.
A standard form submit sends a new HTTP request (POST or GET) and loads the new page in the browser. In Ajax, the data is sent to the server (POST or GET) in the background, without affecting the page at all, and the response is then received by javascript in the background, again without affecting the page at all.
With the help of the event. preventDefault() method the event is to be stopped the form execution.
This does it. I need .live to get it to persist for future events. I just got the syntax wrong multiple times.
$('#comment_body').live('keydown', function(e) {
if (e.ctrlKey && e.keyCode === 13) {
$('#comment_submit').trigger('submit');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With