Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting a comment when pressing enter in Textarea

How do i force a comment by pressing enter? At the moment when i press enter it builds a new line. I've seen quite a few articles here on SO but I can't seem to figure it out.

Here's what I've tried:

function enterForm(event) {
     if(event.keyCode == 13) {
          runForm();
     }
}
function enterForm(event) {
     if(event.keyCode == 13) {
          runForm();
     }
}  

Adding onKeyUp=”enterForm(event)” in the textarea tag. Didn't work.

I also tried something like this:

$('.cmnt_new').on('keyup', function(e) {
    if (e.which == 13 && ! e.shiftKey) {
        // your AJAX call
    }
});

like image 481
cooking good Avatar asked Dec 20 '25 19:12

cooking good


1 Answers

try keypress as found here:

Submitting a form on 'Enter' with jQuery?

$('.input').keypress(function(e) {
    if(e.which == 13) {
        jQuery(this).blur();
        jQuery('#submit').focus().click();
    }
});
like image 135
spojam Avatar answered Dec 22 '25 10:12

spojam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!