aid

Thursday, 26 March 2015

Autocomplete using php ajax and mysql

Many time we want create dynamic box with auto search functionality so we use mostly ajax for it.
Live search demo and auto complete with php mysql
ajax.

<script>
function getcat(str)
  {
   window.XMLHttpRequest
   xml=new XMLHttpRequest();
   xml.onreadystatechange=function()
     {
      if(xml.readyState==4 && xml.status==200)
       {
       
         if(xml.responseText=="")
         {
             alert('Not Found Please search again');
        }
        else {
         document.getElementById("response_cat").innerHTML=xml.responseText;
       
        }
       }
     }
      xml.open("GET","yourfile.php?tech_cat="+str,true);
      xml.send();
 }
 </script>


 HTML Code....

 <input type="text" id="searchBox" placeholder="e.g.-Maths, Dance or Music" autocomplete="OFF" onkeyup="getcat(this.value)">

 <div id="response_cat">
                       
                    </div>

No comments:

Post a Comment