I want to submit a form with keyboard from the following codes:
<form class="article-footnote-form footnote-form" style="margin-top:10px" >
<div class="form-group row">
<div class="col-md-9">
<textarea class="form-control" name="footnote" rows="3" autofocus></textarea>
</div>
<div class="col-md-3">
<button class="btn btn-primary" type="submit" id="articleFootnoteBtn">Add Annotation</button>
</div>
</div>
</form>
I employed the .submit()
shortcut to submit and desire to take advantage of its implicit keypress to submit
$(".article-footnote-form").submit(function(e){
e.preventDefault();
Unfortunately, it did not work, I have to click to submit.
I found a good solution in Enter to submit shift+enter to feedline
$("#textareaId").keypress(function (e) {
if(e.which == 13 && !e.shiftKey) {
$(this).closest("form").submit();
e.preventDefault();
return false;
}
});
However, when changed the triggering event, I should updated bulks of codes depending on the previous.
Could make $("form").submit() working on textarea just it does on input type="text"?