E
E
eldar_web2015-09-28 11:46:05
JavaScript
eldar_web, 2015-09-28 11:46:05

How to avoid form submission by hitting Enter in HTML???

There is a form. If you press Enter, then it works, but how can you avoid this?
Is it possible to do this with jQuery?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
ummahusla, 2015-09-28
@eldar_web

function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey;

Here's another option:
$('html').bind('keypress', function(e)
{
   if(e.keyCode == 13)
   {
      return false;
   }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question