I cannot get the dropdown field to "autosuggest".
I have my main page, which is bpSearch.php, where I have a modal window with an input field that, when you begin typing, it should autosuggest data that is being called from my search file.
Here is the input inside the modal:
<input type="text" class="autosuggest" id="partnerName" name="partnerName" placeholder="Partner Name" />
<div class="dropdown">
<ul class="result"></ul>
</div>
Here is my javascript, called searchPartner.js, that is sending the RESULT to the search file:
$(document).ready(function()
{
$('.autosuggest').keyup(function()
{
var search_term = $(this).attr('value');
$.post('api/searchPartner.php', {search_term:search_term}, function(data)
{
$('.result').html(data);
$('.result li').click(function()
{
var result_value = $(this).text();
$('.autosuggest').attr('value', result_value);
});
});
});
});
And here is my search file, called searchPartner.php. As you can see in the JavaScript, it is located in a folder called api. Perhaps I'm not traversing to the directory correctly? Here is searchPartner.php:
<?php
include("../include/database.php");
if(isset($_POST['search_term']) == true && empty($_POST['search_term']) == false)
{
$search_term = mysqli_real_escape_string($_POST['search_term']);
$search = "SELECT PARTNER_CODE, FULL_NAME FROM partner WHERE FULL_NAME LIKE '$search_term%'";
$query = mysqli_query($dbc, $search);
while(($row = mysqli_fetch_assoc($query)) !== false)
{
echo '<li>', $row['FULL_NAME'], '</li>';
}
}
?>
I know this query works, because I've opened the page, commented out the IF statement, and I can see the LI tags with the $row{'FULL_NAME']. So all I need to do is get my main page to retrieve this data when the user begins typing.