Good morning! I'm having trouble with an application, which happens; 1 - I have this guy who gets the product name and shows my list:
var req;
function buscarProd(valor) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "system/pedidos/data.php?valor=" + valor;
req.open("Get", url, true);
req.onreadystatechange = function () {
if (req.readyState == 1) {
document.getElementById('resultado').innerHTML = '<div class="buscprod">Buscando produto...</div>';
}
if (req.readyState == 4 && req.status == 200) {
var resposta = req.responseText;
document.getElementById('resultado').innerHTML = resposta;
}
}
req.send(null);
}
along with this:
$Valor = filter_input(INPUT_GET, 'valor', FILTER_DEFAULT);
if (empty($Valor)):
exit;
endif;
$Like = "%{$Valor}%";
$Read = new Read;
$Read->ExeRead("produto", "WHERE descricao LIKE :val ORDER BY descricao ASC", "val={$Like}");
foreach ($Read->getResult() as $Produtos):
?>
<form name="FormProd" id="FormProd" method="post" action="#">
<table style="width: 100%; text-align: left;">
<tr><td><input type="hidden" value="<?php echo $Produtos['codigo']; ?>" name="codpro"/></td></tr>
<tr>
<td colspan="3">
<?php echo $Produtos['descricao']; ?>
<td>
</tr>
<tr>
<td colspan="1">
<input style="padding-left: 4px; padding-right: 4px;" name="qntpro" type="number" placeholder="Qnt" />
<td>
<td style="display: none"><input name="nome_usu" type="hidden" value="<?php echo $userlogin['nome_usu']; ?>"/></td>
<td style="width: 60px;">
<input type="submit" name="btnForm" class="circleCar right icon-add" value="Add"/>
<!--<div class="icon-add"></div>-->
<td>
</table>
</form>
<?php
endforeach;
?>
The problem is that when I search for a product appears several in below with the same letter tracking I typed in the search, so far so good, I put the quantity in 1 product and give an add, the page of a refresh and I add this product in my table and I do the research again and add another, and another and another, but sometimes I search and I already see the 3 products I want, but I can not register the 3 at a time because my page of one refresh, I wanted to do this with ajax, so ajax does not seem to work in this method, since I already tried to use e.preventDefault()
return false and it keeps updating the page, can anyone help me?
Remembering, I'm giving the foreach on a form, ie each product is in 1 form with an input for its quantity.