FooKelvin Posted December 4, 2015 Share Posted December 4, 2015 Hi, i have to created two pages. index.php search.php The field from index.php will call search.php. search.php is handling all the database and return back to index.php. For now, i able to call listed the items, just when i want to select one of the listed iteam, and reflect for other fields, it no response. <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/> <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css"/> <form action="" method="post"> <input type="text" placeholder="Name" id="customerAutocomplte" class="ui-autocomplete-input" autocomplete="off" /> <input type="text" id="Name"> </form> <script type="text/javascript"> $("#customerAutocomplte").autocomplete({ source: function( request, response ) { $.ajax({ url: "search.php", data: {term: request.term}, dataType: "json", success: function( data ) { response( $.map( data.myData, function( item ) { return { label: item.Name, value: item.id } })); }, select: function(event,ui){ $("#Name").val(ui.item.Name); } }); } }); </script> <?php //connect to your database require 'databaseConnection.php'; $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $sql = "SELECT Name,[Employee ID] As id FROM headcount WHERE [Employee ID] LIKE '%".$term."%'"; $stmt = sqlsrv_query($conn, $sql); $options = array(); while (list($name, $empid) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { $options['myData'][] = array( 'Name' => $row_id['Name']=$name, 'id' => $row_id['id']=$empid ); } echo json_encode($options);//format the array into json data ?> Quote Link to comment https://forums.phpfreaks.com/topic/299640-autocomplete/ Share on other sites More sharing options...
Psycho Posted December 4, 2015 Share Posted December 4, 2015 Ok. So, did you have a problem or a question? All you did was state what you have done but not provided anything about any errors or what you want to do differently. Quote Link to comment https://forums.phpfreaks.com/topic/299640-autocomplete/#findComment-1527557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.