javascript prevent form submit on enter key

 

 

 

 

In this post, i will show you how to prevent form submitting on enter key with except textarea using javascript code. You can simply do this on your php, laravel, codeigniter, asp.ent etc project. In a web page, normally pressing enter when any form element has focus will submit the form.So I wrote some javascript to translate the enter into a tab when possible (IE) and prevent the formget character code of key pressed if (e.keyCode) numCharCode e.keyCode else if (e.which) if you just want to disable submit on enter and submit button too use forms onsubmit event. not 100 work a regular submit a key best use jquery to prevent.In other words, there are cases where you only want to submit via javascript/jQuery. Some people are pressing the enter key instead of the tab key to get to the next field.If a browser regards hitting ENTER in a text input field as a request to submit the form immediately, there is no sure way to prevent that. Prevent a FORM SUBMIT with ENTERTag(s): Form. To submit the form only when user click the SUBMIT button.