title: How to make two search engine functions combined
body: <p>I have a search engine which display live results,but i second function with it,which is on clicking on my submit button user to be redirected in result page.
  There is my live search in action(still a demo version)<a href="https://i.stack.imgur.com/JR4yL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JR4yL.png" alt="example1"></a>
  And There is code for it:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery(document).ready(function ($) {
   $("#food_search").keyup(function(event){
    var search_term =$(this).val();
  $.ajax({
   type:"POST",
   url:"http://page.com/bg/%D1%82%D1%8A%D1%80%D1%81%D0%B5%D0%BD%D0%B5-%D0%BD%D0%B0-%D1%85%D1%80%D0%B0%D0%BD%D0%B8/",
   data:{'fsearch':search_term},
   success:function(res){
    $("#food_search_result").html(res);
    console.log(res);
   },
   error: function (xhr, ajaxOptions, thrownError) {
             alert(xhr.status);
             alert(xhr.responseText);
             alert(thrownError);
         }
     });
   });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!----------------------------------------------------------------
                              HTML
  -----------------------------------------------------------------&gt;
  &lt;form method="post" accept-charset="utf-8"&gt;
  &lt;input type="text" name="fsearch" id="food_search"&gt;
  &lt;button  id="search-button" type="submit"&gt;&lt;i id="button-icon"&gt;&lt;/i&gt;&lt;span id="button-text"&gt;Търсене..&lt;/span&gt;&lt;/button&gt;
  
  &lt;/form&gt;
  &lt;div id="food_search_result"&gt;
  &lt;?php
  
  If(isset($_POST['fsearch'])){
  var_dump($_POST['fsearch']);
  } 
  // printing the results here in my div(for live search)
  ?&gt;
  &lt;/div&gt;
  
  &lt;!----------------------------------------------------------------
                                PHP
  -----------------------------------------------------------------&gt;
  &lt;?php /*Template Name:Food-Search.php*/ ?&gt;
  &lt;?php
  $hostname = "localhost";
  $username = "name";
  $password = "password";
  $databaseName = "DB NAME !";
  $connect = new mysqli($hostname, $username, $password, $databaseName);
  $connect-&gt;set_charset("utf8");
  $fsearch= "";
  
  if(!empty($_POST['fsearch'])) {
  $fsearch =$_POST['fsearch'];
  
  $req = $connect-&gt;prepare("SELECT title FROM food_data_bg WHERE title LIKE ?");
  $value = '%'.$fsearch.'%';
  $req-&gt;bind_param('s', $value);
  $req-&gt;execute();
  $req-&gt;store_result();
  $num_of_rows = $req-&gt;num_rows;
  $req-&gt;bind_result($title);
  if ($req-&gt;num_rows == 0){
  
  echo 'Няма резултати';
  }
  else{
  while($data=$req-&gt;fetch()){
     ?&gt;
         &lt;div class="search-result"&gt;
             &lt;span class="result-title"&gt;&lt;?php echo $title; ?&gt;&lt;/span&gt;
         &lt;/div&gt;
         &lt;?php
         }
  var_dump($_POST['fsearch']);
  $req-&gt;free_result();
      }
  }</code></pre>
  </div>
  </div>
  
  This code is working fine,except i need it to work on click "Enter" button(on keyboard) or submit button(as i already mentioned above)SO my question is:
  1.Should i make brand new ajax POST method for my button with id #search-button.
  If i must connect 2 functions in one can somebody please give me advice on how to start the new function or give me a link to thread which can help me with writing the new function.</p>
  
  <p>Sorry if i have confused you guys,i am pretty confused too haha . THANKS !</p>