I have a mysql table client
:
client_id client_address client_name
.
I am using js autocomplete, that brings back the value client_address
based in the selected input.
The label used is address
and name
, and the value brought back is client_address
. I am already using the select callback to use the ui
in another ajax script that shows an html table.
<script type="text/javascript">
$(function() {
$( "#clientsearch" ).autocomplete({
source: 'backend_search_addressWT.php',
minLength: 2,
select: function(event, ui) {
showUser(ui.item.value)
}
});
});
</script>
backend_search_addressWT.php:
<?php
require_once 'config.php';
//get search term
$searchTerm = $_GET['term'];
//get matched data from skills table
$query = $mysqli->query("SELECT * FROM client WHERE client_address LIKE '%".$searchTerm."%'");
while ($row = $query->fetch_assoc()) {
$data[] = array (
'label' => $row['client_address'].' - '.$row['client_name'],
'value' => $row['client_address'],
);
}
//return json data
echo json_encode($data);
?>
What I would like to do is get the client_id
for the selected client, to be submitted as a hidden variable in the form.
How do I get the client_id
to be brought back as a separate value? I have tried adding on a value2 to the array, and then using the select function on this:
select: function(event, ui) {
showUser(ui.item.value),
$('#hiddenID').ui.item.value2
}
But this seems to throw off the autocomplete. Should I add it to the label and then try split it?
I have looked at Get value in jquery autocomplete but I am already using the select
.
Dont use comma (,) use ; becouse you are writing code inside function. try as below.
select: function(event, ui) {
showUser(ui.item.value);
$("#hiddenID").val(ui.item.value);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.