w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
I am using ajax to show the output after entering some data on textfield ,it is not showing proper output?

The approach should be

  1. Write onchange event (onchange of textbox content call the process() function) for the text box.

  2. To add a button to triggering the function. => user enters the dish and clicks on button.

Approach one (Using jQuery)


<script type="text/javascript"
<!--<script type="text/javascript"
    $(document).on("keyup","#inputuser", function(){

        var dish = $(this).val();

          type: "GET",
          url: 'foodstore.php',
          data : {food:dish},
          success: function(data){alert(data);
    <h1>choose your favorite food</h1>
    <input type="text"  id="inputuser" value="" />
    <div id="usererror"></div>


$foodArray=array('shahi paneer','matar paneer','matar alu','raita');
if(in_array($food,$foodArray)) {
   echo 'we  do have '.$food.'!'; 
elseif($food=='') { 
   echo 'please enter any dish';
} else  {
   echo 'we dont have '.$food.'!';


© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.