Jquery autocomplete from remote database

Jquery autocomplete from remote database

Hello,

I want to implement a simple jquery autocomplete into openemr.I have a textbox and I want to display all the diagnoses code while the user is typing the first letters of an illness.My code so far is:

main.php

  1.   <input id='searching' type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
  2.     title='<?php echo xla('Any part of the desired code or its description'); ?>' />
  3.    &nbsp;

  4.   <meta charset="utf-8">
  5.   <title>jQuery UI Autocomplete - Remote datasource</title>
  6.   <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  7.   <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  8.   <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  9.   <script>
  10.   $(function() {
  11.     function log( message ) {
  12.       $( "<div>" ).text( message ).prependTo( "#log" );
  13.       $( "#log" ).scrollTop( 0 );
  14.     }
  15. $("#searching").autocomplete({
  16.                 source: "search_ajax.php",
  17. minLength: 2,
  18.                 select: function(event, ui) {
  19.                     $('#searching').val(ui.item.id);
  20.                 }
  21.             });
  22.   });
  23.   </script>

search_ajax.php

  1. <?php
  2. if(isset($_REQUEST['search_term']))
  3. {
  4.     $search_term2=$_REQUEST['search_term'];
  5. }
  6. else
  7. {
  8.     header("HTTP/1.0 403 Forbidden");    
  9.     echo "No search parameter specified";   
  10.     return false;
  11. }
  12. if(isset($_REQUEST['search_type']))
  13. {
  14.     $search_type=$_REQUEST['search_type'];
  15. }
  16. else 
  17. {
  18.     $search_type='ICD9';
  19. }
  20. if(isset($_REQUEST['search_type_id']))
  21. {
  22.     $search_type_id=$_REQUEST['search_type_id'];
  23. }
  24. else
  25. {
  26.     $search_type_id=2;
  27. }
  28.       $retval=array();
  29.     $search=main_code_set_search($search_type,$search_term2,20);
  30.     while($code=sqlFetchArray($search))
  31.     {
  32. array_push($retval,new code_info($code['code'],$search_type,$code['code_text']));
  33.     }
  34. $array[0]=$retval;
  35. echo json_encode($array);


  36. ?>