I'm trying to make this happen:
prevent a submit button from submitting the form
fade an element out
then submitting the form
But am stuck with an infinite loop of animation! Why??
HTML
<form id="postitron" method="post" action="/postitron/answertron.php">
<input type="hidden" name="acces" value"yes">
<input id="submit" type="submit" value="DOIT">
</form>
JavaScript
$('#postitron').submit(function(e){
e.preventDefault();
$('#page').animate({opacity:0},400, function(){
$('#postitron').submit();
});
});
P.S.- I've also tried the .one()
method instead of .submit()
, but it prevents the submit method from being executed on #postitron once the animation's complete :(
It is because you are binding your event on
SUBMIT
, and your.animate callback function
isSUBMIT
'ing the form...causing the infinite loop.Try this :
Instead of binding event
.submit
onform
, bind.click
event onsubmit
button.Bare in mind I did not test this.
You could pre-define the function, and within it, unbind to submit, then re-submit. It's a hack, but it may work.
Or perhaps you check for it's hidden-ness and then resubmit like this:
submit()
calls your custom boundsubmit
function, which in turns call yoursubmit
again etc.Try using DOM's submit:
$('#postitron')[0].submit()