Do you speak well?
I have an HTML application, PHP, Jquery, bootstrap and on the same screen I have two tables the first of clients I bring via AJAX when I type the client name in the "search" field, this returns me a table with name, cpf and a "select customer" button, this button select client when it is generated by "while" I already enter in your attribute "value" the client id for when I select it know who I am talking about. but when I select the client in the list, it has "value" as undefined, I need to select the client and then in the second table on the same screen, select only the products purchased by him by filtering through his ID.
I thought of doing this as here Get value or name of the button with JQuery
AJAX:
function CriaRequest() {
try{
request = new XMLHttpRequest();
}catch (IEAtual){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(IEAntigo){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(falha){
request = false;
}
}
}
if (!request)
alert("Seu Navegador não suporta Ajax!");
else
return request;
}
function getDadosCliente() {
var nome = document.getElementById("buscarcliente").value;
var result = document.getElementById("ResultadoCliente");
var xmlreq = CriaRequest();
result.innerHTML = '<img src="../img/loading.gif"/>';
xmlreq.open("GET", "buscarcliente.php?buscarcliente=" + nome, true);
xmlreq.onreadystatechange = function(){
if (xmlreq.readyState == 4) {
if (xmlreq.status == 200) {
result.innerHTML = xmlreq.responseText;
}else{
result.innerHTML = "Erro: " + xmlreq.statusText;
}
}
};
xmlreq.send(null);
}
findclient.php (what AJAX calls):
<?php
if (isset($_GET["buscarcliente"])) {
$nome = $_GET["buscarcliente"];
if (empty($nome)) {
$query = ("SELECT * FROM clientes");
} else {
$nome .= "%";
$query = ("SELECT * FROM clientes WHERE nomeCliente LIKE '$nome'");
}
sleep(1);
$dados = mysqli_query($conecta,$query);
// transforma os dados em um array
$linha = mysqli_fetch_assoc($dados);
// calcula quantos dados retornaram
$total = mysqli_num_rows($dados);
$cont = mysqli_affected_rows($conecta);
if($cont > 0) {
$tabela = "<table class='table table-striped table-bordered table-hover'>
<thead>
<tr>
<th class='text-center info'>NOME</th>
<th class='text-center info'>CPF/CNPJ</th>
<th class='text-center info'>AÇÃO</th>
</tr>
</thead>
<tbody>
<tr>";
$return = "$tabela";
do{
$return.= "<td>" . utf8_encode($linha['nomeCliente']) . "</td>";
$return.= "<td>" . utf8_encode($linha['cpfcnpj']) . "</td>";
$return.= "<td class='text-center'><a onclick='selecaoCliente()' class='btn btn-success btn-sm' value=".$linha['idCliente']."><span class='glyphicon glyphicon-ok'></span></a></td>";
$return.= "</tr>";
} while ($linha = mysqli_fetch_assoc($dados)) ;
echo $return.="</tbody></table>";
} else {
echo "Não foram encontrados registros!";
}
}
?>
In HTML I only have the input fetch, the result div, the textarea, and the second fetch field with the second result div.