Function with delay

0

My scenario is as follows, I have a link and would like it after clicking it after 3 seconds submit a form. I'm 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);
 });
    
asked by anonymous 31.03.2018 / 02:48

1 answer

1

Use the on() method of jQuery and get the form by id in 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><ahref="#" target="_blank" id="envia-form">Link</a>

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