0
Talk personal all right?
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, it returns me a table with name,Cpf and a button "select client", this select client button when it is generated by "while" I already enter in your attribute "value" the client id for when I select it know who I’m talking about. however when I select the customer in the list, it brings the "value" as undefined, I need to select the customer to then in the second table of the same screen select only the products purchased by him filtering by his ID.
I thought I’d do like this answer here Pick up value or button name with Jquery
but it brings "value" as undefined, when I click with the direct mouse button and inspect, it is with the correct "value", but when I click does not fill my Textarea.
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);
}
buscarcliente.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 search input, result div, textarea, and the second search field with the second result div.
Alexandre, post the code so we can assist you.
– Jorge.M
edited the question and put the code
– Alexandre
It would be interesting to post the
HTML
also. The more information, the easier your question receives attention.– Jorge.M
Failed to put the function code
selecaoCliente()
to see how it’s being done.– Sam