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
- <script type="text/javascript">
-
- $(function() {
-
- $("#name").autocomplete({
- source: "addresssearchautosuggest.php",
- //source: "hitgujindexautocompletefill",
- minLength: 2,
- select: function(event, ui) {
- var getUrl = ui.item.id;
- if(getUrl != '#') {
- location.href = getUrl;
- }
- },
-
- html: true,
-
- open: function(event, ui) {
- $(".ui-autocomplete").css("z-index", 1000);
- }
- });
-
-
-
- });
PHP :
- <?php
-
- include_once("includes/dbconnect.php");
- include_once("functions.inc.php");
-
-
-
- $user_input = trim($_REQUEST['term']);
-
- $display_json = array();
- $json_arr = array();
-
-
- $user_input = preg_replace('/\s+/', ' ', $user_input);
-
-
- $query = 'SELECT id,name,serviceid, subserviceid, cityid FROM address WHERE name LIKE "%'.$user_input.'%" order by name';
-
-
- mysql_select_db($database_DBconnect, $DBconnect);
- $Result = mysql_query($query, $DBconnect) or die(mysql_error());
- $rows = mysql_fetch_assoc($Result);
- $totalrows=mysql_num_rows($Result);
- $recSql = mysql_query($query);
- if(mysql_num_rows($recSql)>0){
- while($recResult = mysql_fetch_assoc($recSql)) {
- // $json_arr["id"] = "http://www.cancerdirectory.org/address.php?id=".$recResult['id'];
-
- $json_arr["value"] = $recResult['name'].' - '.$recResult['serviceid'] ;
- $json_arr["label"] = $recResult['name'].' - '. Servicename($recResult['serviceid']).' - '.Cityname($recResult['cityid']);
-
- array_push($display_json, $json_arr);
- }
- } else {
- $json_arr["id"] = "#";
- $json_arr["value"] = "";
- $json_arr["label"] = "Could not Find Name -> ".$user_input."<br> try Another Name";
- array_push($display_json, $json_arr);
- }
-
-
- $jsonWrite = json_encode($display_json); //encode that search data
- print $jsonWrite;
- ?>
- } else {
- $json_arr["id"] = "#";
- $json_arr["value"] = "";
- $json_arr["label"] = "No Result Found !";
- array_push($display_json, $json_arr);
- }
-
-
- $jsonWrite = json_encode($display_json); //encode that search data
- print $jsonWrite;
- ?>