James Baloni
James Baloni

Reputation: 147

Make enter key click search button

I am having trouble making enter key to hit the search button.... Please help me out. Thank you in advance.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
........
    <script type="text/javascript" src="js/jquery.js"></script>
<script src="../jQueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script><script type="text/javascript">  


             function get() {
                  $.post ('data/data.php', { word: form.name.value },
                          function (output) {

                        $('#defination') .html(output).show() ;

                    });
             }       
    </script>        
.............

<form name ="form">
  <div align="center">
    <pre> <input name="name" type="text" autofocus required placeholder="Please enter a Word !"  size = "70" maxlength="50" >
    </pre>

    <p>
      <input type="button" onClick="get();" value="Search" size = "30" >
    .........
</html>

Upvotes: 2

Views: 2977

Answers (2)

BenI
BenI

Reputation: 93

This will also work:

$(document).bind("keydown", function(event){
 if(event.which=="13")
   {
    $("form").submit();
   }
});

Upvotes: 0

Harshit Tailor
Harshit Tailor

Reputation: 3281

you can use JQuery to submit form.

$(document).bind("keydown", function(event){
  if(event.which=="13")
   {
      $("#buttonID").click();
    }
});

Upvotes: 2

Related Questions