this is my code ... The problem is that when i click on autocomplete suggestion it submits the from with only the information i've written to input and not the selected autocomleted word. I guess it's because the form gets submitted faster then the input gets autocompleted. But how do i solve it?
<form id="searchForm" action="../chat/chat.php" method="POST">
<input id="search" type="text" name="getter" value="" placeholder="Search for user">
</form>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$("#search").autocomplete({
source: "selector.php",
minLength: 1,
select: function(event, ui) {
$("#searchForm").submit();
}
});
});
Here is the selector.php ... I dont know if you need it but still->
<?php
include_once "../additional_code/dbh.inc.php";
$return_arr = array();
$searchTerm = $_GET["term"];
$sql = "SELECT user_uid FROM users WHERE user_uid LIKE '%" . $searchTerm . "%' ";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
$return_arr[] = $row['user_uid'];
}
echo json_encode($return_arr);