autosugegst : How to Avail id of the name selected

autosugegst : How to Avail id of the name selected

Dear Sir

refer


My Auto suggest is working

What i want is 
1. User selects  a name from the list displayed
2. this selected name will be displayed in text box he/she is typing
  <<< everything working fine till here >>>
3. I want user to click Submit so as to display the details of the name selected by him
4. for this i feel i should avail  of record clicked

I donot want to display the details by opeing new link ... when  clicked on  the list of a name  in Autosuggest name box
 
I am using

1.   <script src="javascript/jquery-1.11.2.min.js"></script>
2.  <script type="text/javascript" src="javascript/jquery-ui-1.8.2.custom.min.js"></script> 
        (do not know anything about this\ but using it)

JQuery
  1. <script type="text/javascript">
  2.  
  3. $(function() {
  4.  
  5. $("#name").autocomplete({
  6.  source: "addresssearchautosuggest.php",
  7. //source: "hitgujindexautocompletefill",
  8. minLength: 2,
  9. select: function(event, ui) {
  10. var getUrl = ui.item.id;
  11. if(getUrl != '#') {
  12. location.href = getUrl;
  13. }
  14. },
  15.  
  16. html: true,
  17.  
  18. open: function(event, ui) {
  19. $(".ui-autocomplete").css("z-index", 1000);
  20. }
  21. });

  22.  
  23.  
  24. });


PHP  :

  1. <?php
  2.  
  3. include_once("includes/dbconnect.php");
  4.   include_once("functions.inc.php");

  5.  
  6. $user_input = trim($_REQUEST['term']);

  7.  $display_json = array();
  8. $json_arr = array();
  9.  

  10. $user_input = preg_replace('/\s+/', ' ', $user_input);

  11.  
  12. $query = 'SELECT  id,name,serviceid, subserviceid, cityid     FROM address    WHERE  name LIKE "%'.$user_input.'%" order by  name';

  13.  
  14.  mysql_select_db($database_DBconnect, $DBconnect);
  15. $Result = mysql_query($query, $DBconnect) or die(mysql_error());
  16. $rows = mysql_fetch_assoc($Result);
  17. $totalrows=mysql_num_rows($Result);
  18. $recSql = mysql_query($query);
  19. if(mysql_num_rows($recSql)>0){
  20. while($recResult = mysql_fetch_assoc($recSql)) {
  21.  // $json_arr["id"] = "http://www.cancerdirectory.org/address.php?id=".$recResult['id'];  
  22.  
  23.   $json_arr["value"] = $recResult['name'].' - '.$recResult['serviceid'] ;
  24.   $json_arr["label"] = $recResult['name'].' - '. Servicename($recResult['serviceid']).' -  '.Cityname($recResult['cityid']);
  25.  
  26.   array_push($display_json, $json_arr);
  27. }
  28. } else {
  29.   $json_arr["id"] = "#";
  30.   $json_arr["value"] = "";
  31.   $json_arr["label"] = "Could not Find Name -> ".$user_input."<br> try Another Name";
  32.   array_push($display_json, $json_arr);
  33. }
  34.   
  35. $jsonWrite = json_encode($display_json); //encode that search data
  36. print $jsonWrite;
  37. ?>
  38. } else {
  39.   $json_arr["id"] = "#";
  40.   $json_arr["value"] = "";
  41.   $json_arr["label"] = "No Result Found !";
  42.   array_push($display_json, $json_arr);
  43. }
  44.   
  45. $jsonWrite = json_encode($display_json); //encode that search data
  46. print $jsonWrite;
  47. ?>