Hi i was im trying to make a jquery ajax submit form, and im currently trying to make restrictions for submiting a form.
i want the user to press enter to submit a form and not press on a submit button,
but only when the user is focusing on a textarea/input field it will submit when he/she presses enter!
i have attempted to make my own code and edit in it to see what works,
and i have figured this code out, but it doesnt work quite well 🙁
$('.addformtextarea').focus(function() {
$(document).keyup(function(e){
switch (e.keyCode) {
case 13: //enter
//code to be
break;
}
});
.addformtextarea is the textarea to be focused on.
and does return false; behave the same as break; ? because i have a return false; right before break;
thanks 😀
Try this:
You don’t need to worry about focus, because the keyup would only fire if the input has focus.
The break only breaks out of the switch, you need return false to prevent the automatic submit, if you are doing it with the code.