Delayed function

Asked

Viewed 26 times

0

My scenario is the following, I have a link and I would like after clicking it after 3 seconds submit a form. I am trying the following

 <a href="" target="_blank" id="acionabotao">Link</a>

 <form method="post" action="acao.php">
 <input name="" value="">
 <button type="submit" id="clickatrasado">
 </form>

 $("#acionabotao").click(function(){
 setTimeout(function() {
 $("#clickatrasado").trigger('click');
 }, 1000);
 });

1 answer

1


Use the method on() jQuery and take the form by id this way just use submit()

$('#envia-form').on('click', function() {
    setTimeout(function() {
        $('#form-target').submit()
    }, 3000)
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" target="_blank" id="envia-form">Link</a>

 <form id="form-target" method="post" action="./?">
     <input type="hidden" name="oculto" value="xxxx">
 </form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.