Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form - when I hit enter it refreshes page! [duplicate]

Is there a way to make a form NOT refresh or call anything when you hit "Enter" key on your keyboard?

Thank you so much!!!

I found this code for preventing Enter from working, but it DOESN'T work in IE :(

  $(document).ready(function() {   $(window).keydown(function(event){     if(event.keyCode == 13) {       event.preventDefault();       return false;     }   }); } 
like image 946
Sharon Avatar asked Feb 07 '10 01:02

Sharon


People also ask

How do I stop a page from refreshing on a form?

Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.

How do I stop HTML form from refreshing after submitting?

Use jQuery's submit event to handle the form submit, add return false; at the end of the submit handle function to prevent the page to reload. return false ; });

How do I stop resubmission when a page is refreshed in PHP?

Unset Form Data One way to stop page resubmission on page refresh is to unset the form data after it is submitted so that the variable storing form data becomes empty and wrap up your form processing block of codes to check if the form is empty.

How do you refresh the same page in HTML?

Most people know it can be done by hand by holding the shift key and clicking the “Refresh” (on IE) or “Reload” (on Navigator) buttons.


1 Answers

Try this:

$(function() {     $("form").submit(function() { return false; }); }); 
like image 100
icktoofay Avatar answered Sep 29 '22 22:09

icktoofay