2
Good morning Galera,
I have in my home , a field to consult CPF. The field has only one text field , where I inform the CPF, if I find some Cpf in the database , it returns me some data.I submit the form with ajax , not to reload the page , on the page that makes the query , I play the data in an array and convert it to json , recover the value in my home and print them.
The div that showed the data, I leave it hidden: <style>style:display:none;</style>
When I press the button to search, it displays a table with the data :
<script>
$("#btnConsulta").click
(
function()
{
var show = $("#divForm").css("display","block");
}
);
</script>
ate ai blz. But I would like the div with this table to be hidden again ,apos x seconds.
fix the code :
function hideDiv()
{
$("#divForm").css("display","none");
}
And I used setInterval to run it after x seconds. But if I define that I will call the hide function in 10 seconds , if I enter the page , wait 5 seconds and search , my div will only be visible for 5 more .
I would like the setInterval to start counting after I press the search button.
EDIT :----------
Code I use to submit the form and take the data.
<script type="text/javascript">
function consultaCpf()
{
jQuery(document).ready(function(){
jQuery('#form1').submit(
function(){
var dados = jQuery( this ).serialize();
jQuery.ajax
(
{
type: "POST",
url: "/admin2/inc/ajaxSubmit/consultaCpf.php",
data: dados,
dataType: "json",
success: function(json)
{
$('#nomeVendedor').html( json.vendedor);
$('#nomeCliente').html( json.cliente );
$('#cpfCliente').html( json.cpf );
}
}
);
return false;
});
});
}
consultaCpf();
</script>
Here he sends the form to the page consultCpf.php.
On the page consultCpf.php :
$return = array();
$cpf = $_POST['txtCpf'];
$sql = mysql_query("SELECT vendedor,nomeCliente,cpf
FROM tblVenda where cpf = '$cpf' ");
while($row = mysql_fetch_array($sql))
{
$vendedor = $row['vendedor'];
$cliente = $row['nomeCliente'];
$cpf2 = $row['cpf'];
}
$return['vendedor'] = $vendedor;
$return['cliente'] = $cliente;
$return['cpf'] = $cpf2;
echo json_encode($return);
From now on, grateful
setTimeout
!=setInterval
– Caio Felipe Pereira
Good morning Caio , I tried to use your code , but the div was not shown.
– Henrique Felix
True, but for the confusion ^^
– Renan Gomes
@re22 Happens.
– Caio Felipe Pereira
@Henriquefelix is this what you want to do? http://jsfiddle.net/wqyvpru3/1/
– Caio Felipe Pereira
@Caiofelipepereira , exactly ! I accessed the link above , and tested it here and it worked . Thank you very much!
– Henrique Felix
I’ll edit my answer then
– Caio Felipe Pereira
This solution has the bug I mentioned in my reply - try clicking the button several times, wait for the div to disappear, and then click the button again - the div will close in less than 5 seconds.
– user25930
@ctgPi truth.
– Caio Felipe Pereira
Vish , I tested and the business gets bugged. But the consultations that the people do here is very little . The code of @ctgPi , I will use it in a page that I do constant update , and was receiving this problem. The page updates the values with a button , but the setinterval automatically updated tbm . So , I do not spend much resource , if pressed the button ,it counts more 15 seconds to update .
– Henrique Felix
If the @ctgPi response was helpful to you, mark it as correct!
– Caio Felipe Pereira