Pages

Thursday 13 February 2014

How jQuery Stop Form being Submitted on Enter Key Press or Disable Form Submit on Enter

How jQuery Stop Form being Submitted on Enter Key Press or Disable Form Submit on Enter


 $(function ()
{
 $("form").submit(function (e)
 {
 event.preventDefault();
 return false;
 });
 })


Method 1:


 $(function ()
 {
 $(window).keydown(function (event)
{
 if (event.keyCode == 13)
{
 event.preventDefault();
 return false;
  }
 });
 });


Method 2:



$("form").bind("keypress", function (e) { if (e.keyCode == 13) return false; });


Download

No comments:

Post a Comment