Hi,
I am using the following jquery and PHP to populate an autocomplete. I will add a btnShowDetails and I woudl like to let the btnShowDetails read the value of the autocomplete (which is the company_guid? How can I do this please.
jquey for autocomplete:
$("input#txtCompanyName").autocomplete
(
{
source : function (request, callback)
{
var data = { term : request.term };
$.ajax
(
{
url : "../autocomplete_company.php",
data : data,
search : function(){$(this).addClass('working');},
open : function(){$(this).removeClass('working');},
complete : function (xhr, result)
{
if (result !== "success") return;
var response = xhr.responseText;
var autocomplete_result = [];
$(response).filter ("li").each (function ()
{ autocomplete_result.push ($(this).text ());
}
);
callback (autocomplete_result);
}
}
);
}
});
and it’s reading from this autocomplete_company.php:
<?php
include('includes/php_header.php');
include($_SESSION["absolute_path"] . '/includes/connect2db.php');
$autocomplete_term = utf8_decode($_REQUEST["term"]);
$mysql_command = "CALL sp_autocomplete_company(:param_company)";
$mysql_query = $mysql_connection->prepare($mysql_command);
$mysql_query->bindParam(':param_company', $autocomplete_term, PDO::PARAM_STR);
$mysql_query->execute();
while($mysql_row = $mysql_query->fetch())
{
echo ("<li>" . utf8_encode($mysql_row['company_name']) . "</li>");
}
?>
and here I want to read the autocomplete value:
$('#btnShowDetails').click(function(){
$.ajax({
url : "get_company_details.php",
data : 'id=HERE I WANT TO READ THE VALUE OF THE AUTOCOMPLETE',
type : "post",
success : function(data)
{
here I am displaying the result
}
});
});