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
- <input id='searching' type='text' name='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
- title='<?php echo xla('Any part of the desired code or its description'); ?>' />
-
- <meta charset="utf-8">
- <title>jQuery UI Autocomplete - Remote datasource</title>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
- <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
- <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
- <script>
- $(function() {
- function log( message ) {
- $( "<div>" ).text( message ).prependTo( "#log" );
- $( "#log" ).scrollTop( 0 );
- }
-
- $("#searching").autocomplete({
- source: "search_ajax.php",
- minLength: 2,
- select: function(event, ui) {
- $('#searching').val(ui.item.id);
- }
- });
-
- });
- </script>
search_ajax.php
- <?php
- if(isset($_REQUEST['search_term']))
- {
- $search_term2=$_REQUEST['search_term'];
- }
- else
- {
- header("HTTP/1.0 403 Forbidden");
- echo "No search parameter specified";
- return false;
- }
- if(isset($_REQUEST['search_type']))
- {
- $search_type=$_REQUEST['search_type'];
- }
- else
- {
- $search_type='ICD9';
- }
- if(isset($_REQUEST['search_type_id']))
- {
- $search_type_id=$_REQUEST['search_type_id'];
- }
- else
- {
- $search_type_id=2;
- }
- $retval=array();
- $search=main_code_set_search($search_type,$search_term2,20);
- while($code=sqlFetchArray($search))
- {
- array_push($retval,new code_info($code['code'],$search_type,$code['code_text']));
- }
- $array[0]=$retval;
- echo json_encode($array);
- ?>