Find us on facebook

Aug 29, 2014

Auto complete Text Field jquery-1.9.1.min.js

html file
<?php
include_once $_SERVER['DOCUMENT_ROOT'].COMMON.'/js/js_homewaypoint.php';

?>
<input type="text" name="from_point" id="from_point" class="area-point-text-input"/>
<input type="hidden" id="from_point_id" name="from_point_id"/>
<input type="hidden" id="from_point_table" name="from_point_table"/>
<input type="hidden" id="from_point_type" name="from_point_type"/>
<div id="from_point_error" class="error_bg" style="display: none;">Please Enter Valid Pickup Point</div>

js_homewaypoint.php file
<link rel="stylesheet" href="scripts/jquery/themes/redmond/jquery.autocomplete.css">
<script src="scripts/jquery/autocompleteused/jquery-1.9.1.min.js"></script>
<script src="scripts/jquery/autocompleteused/jquery-ui.min.js"></script>

<script language="javascript">
 $(document).ready(function()
{
$(function() {

$("#from_point").autocomplete({
source: "get_search_values.php",
minLength: 1,
select: function( event, ui ) {
  $('#from_point_id').val(ui.item.id);
  $('#from_point_table').val(ui.item.table);
  $('#from_point_type').val(ui.item.area_type);
  $('#from_point_postcode').val(ui.item.postcode);
if(ui.item.id != ''){
$('#from_point').css("background"," url('styles/images/tick.png') right center no-repeat #ffffff");
$('#from_point_error').hide();
//$("#from-point-container").hide();
//$("#from-point-container-display").show();
}
  return ui.item.label;
 },
});

});
});
</script>

get_search_values.php

$qstring = "SELECT inner_postcode, outer_postcode_suffix, outer_postcode,name,id, area_type, full_postcode,is_address FROM a_area_points WHERE is_display = '1' AND (name LIKE '".$term."%') LIMIT 300";
     $result = mysql_query($qstring);


      while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
      {
                $name = ucwords(strtolower($row['name']));
                $outer_postcode = $row['outer_postcode'];
                $area_type = $row['area_type'];
                if($area_type == 'AIRPORT'):
                    $outer_postcode = "";
                     $label = "$name";
                else:
                     $label = "$name, $outer_postcode";
                endif;
                $outerSuffix = $row['outer_postcode_suffix'];
$inner = $row['inner_postcode'];
$full_postcode="$outer_postcode$outerSuffix $inner";
             
                $id_array[] = $id = (int)$row['id'];
$data[] = array(
'label' => $label ,
'id' => (int)$row['id'],
                        'table' => "a_area_points",
                        'postcode' => $full_postcode,
                        'outer_postcode' => $row['outer_postcode'],
                        'area_type' => $area_type,
                        'is_address' => $row['is_address']
);
               
             
      }
 echo json_encode($data); 

No comments:

Post a Comment