pTutorial

New way to learn Programming

JQuery form submit on enter

JQuery : HTML Form - submit on enter

In this article I showed you on how to submit form on enter using JQuery. You can use following script to submit form data on enter button.

submit on enter example


<!doctype html>
<html lang="en">
<head>
  <script src="http://freeonlinecompiler.ptutorial.com/
js/jquery.min.js"></script>
</head>
<body>
<h2>Submit on enter</h2>
 <form id="f" action="uk.php">
<input id="whichkey"  type="text">
 </form>
<script>
$("#f").on( "keydown", function( event ) {
var key=event.which;
var name = $("#whichkey").val();
if(key==13){
if(name=='')
{
alert("You have not entered anything");
}else{
$('#f').submit();
alert("you have entered: "+name);
}
}
});
</script>
 
</body>
</html>

Download

See Also


QUOTES OF THE DAY

Crafty men condemn studies, simple men admire them, and wise use them.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER