Maybe the .stop
do not perform because it will only be processed on page loading and not on download, I can not affirm with conviction this because I am not sure of the behavior in different browsers engines (Webkit, Blink, Trident, Gecko, etc.)but some paths you could choose are to use cookies or the parameters in querystring (so it doesn’t affect the POST).
Supposing your form is something like:
<form action="?send=1" method="POST">
...
<input type="submit" value="">
</form>
And in Javascript check:
<script type="text/javascript">
//Verifica se tem o GET com "expressão regular"
if (/\?send=1(&|$)|&send=1(&|$)/.test(window.location)) {
$("#enviar").click();
}
</script>
Or if your page uses PHP you can check if one of the POST fields was sent (or better all) using isset
:
<?php if (!isset($_POST['campo1'], $_POST['campo2'], $_POST['campo3'])): ?>
<script type="text/javascript">
$("#enviar").click();
</script>
<?php endif; ?>
The !isset($_POST['campo1'], $_POST['campo2'], $_POST['campo3'])
contains !
and isset
, is a denial, that is if there is no campo1, campo2, campo3, it means it did not come from your FORM and then it will execute the .click
, chance has come from FORM will not enter IF and will not run again.
Adjust the values within isset
to the fields of your FORM.
my form works in PHP on the same page without refresh. So my form looks like this:
form class="form-inline" id="busca" method="POST" action=""
Maybe I haven’t understood your second answer, but let’s see the idea. I already do a check in the
 field;if(!empty($select_empresa)){
 $sql_empresa = "AND empresa_id='$select_empresa' ";
 }
This way, I think your second suggestion does not match the result I need. Actually I need the click to run with the value that is already in the POST fields, and not clean it, maybe I got it wrong.– Marcelo Rossi
@Marcelorossi yes you got it wrong, I gave an example Enerico, because I can’t guess your current PHP structure, since you didn’t post it, right? So just you adapt the code I posted, the above situations are simple examples, adapting will work.
– Guilherme Nascimento
I will try here, adapt as you suggested. Thank you very much for the collaboration.
– Marcelo Rossi