0
Good morning! I’m having problem in an application, what happens; 1 - I have this guy who gets the name of the product 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 research a product appears several below with the same letter following that I typed in the search, so far so good, I put the quantity in 1 product and give an add, a refresh page and add this product in my table and do the search again and add another, and other and other, but sometimes I research and already see face 3 products I want, only I can not register the 3 at once because my page gives a refresh, I wanted to do this with ajax, only ajax doesn’t seem to work in this method, because I tried to use the e.preventDefault()
Return false and it keeps updating the page, someone can help me?
Remembering, I’m giving the foreach in a form, ie each product is in 1 form with an input for your quantity.