1
I have this Jquery code:
<script>
jQuery(document).ready(function(){
// Numero de click
var totalClicks = 0;
jQuery('#addpayment').submit(function(){
var dados = jQuery( this ).serialize();
// Verifica se o valor da variável totalClicks representa 3 clicks.
// Caso o número seja menor que 3 clicks, ignora esse trecho
if (totalClicks >= 2) {
alert("redirecionando");
windows.location......
return false;
}
}
//Soma o valor de totalClicks + 1
totalClicks++;
});
</script>
And this modal:
<form action="" method="post" id="addpayment" name="addpayment" class="form-
horizontal">
<!-- Modal -->
<div class="container">
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h6 class="modal-title">Teste - Modal </h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<!--Fim Modal -->
It needed that after each click appeared the modal above, and in the third click, redirected the user to a page. Modal works, but jquery events (click) do not.
is correctly incrementing the variable totalClicks?
– Ricardo Pontual
Theoretically yes. It takes the click by jQuery('#addpayment'). Submit(Function() and feeds in totalClicks++;. I may be mistaken, but I believe you are right. Unless the problem is in the Modal call breaking this function.
– user54154
tries to put a
console.log(totalClicks)
or aalert(totalClicks)
, may be he’s resetting his counter– Ricardo Pontual
I put the alert (Alert(totalClicks)) inside jQuery('#addpayment'). Submit(Function(){, however only opens the modal, it seems that neither enters the function.
– user54154
does not increment, no... is out of Submit’s Function it adds in Document ready and only
– Leandro Angelo
Not if I know is a mistake when copying the code, but in the example the line
totalClicks++;
is not within the anonymous function.– Filipe Moraes
even though @Leandroangelo commented that he was suspicious.
– Ricardo Pontual