0

On my submit button, I have onclick="list_activity(); but how can I make the list_activity(); function run about 2 seconds after the button is clicked instead of straight away?

HTML code I'm using:

<textarea name="blab_field" id="blab_field" style="width:98%;height:55px;" placeholder="What is on your mind?  - What are you doing right now? - Tag people with @username (username can be found on profiles)"></textarea>

          <input name="mem_id" id="mem_id" type="hidden" value="4" />
          <input name="poster_id" id="poster_id" type="hidden" value="<?php echo $logOptions_id; ?>" />
          <input type="hidden" name="type" id="type" value="a" />
          <input type="hidden" name="device" id="device" value="Google Chrome : Windows 7" />
           <input name="submit" type="submit" style="width:100%;" onClick="post_chat();" class="btn btn-info" value="Post Blab" />
James
  • 576
  • 2
  • 8
  • 20

6 Answers6

4
$('input[type=submit]').on('click', function(){
     setTimeout(list_activity, 2000);                    
}});

UPDATES:

HTML:

<input name="submit" type="submit" style="width:100%;" onClick="post_chat();" class="btn btn-info" value="Post Blab" />

JS:

  <script type="text/javascript">
    function post_chat() {
        setTimeout(list_activity, 2000); 
            //your todos
    }

    function list_activity() {
        //your todos 
    }
    </script>
Praveen
  • 55,303
  • 33
  • 133
  • 164
2

What you need is setTimeout()

Calls a function or executes a code snippet after specified delay.

Your list_activity function should like

function list_activity (
        setTimeout(function () {
                              formid.submit();
                        }, 2000);                    
                  }

}
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

You can use it.

setTimeout(function() { your_function(); }, 2000);
delibalta
  • 300
  • 2
  • 11
1

Just have it in a setTimeout:

onclick="setTimeout(list_activity, 2000);"
Amberlamps
  • 39,180
  • 5
  • 43
  • 53
0

Maybe the SetTimeOut method can be usefull to you :

setTimeout(myFunction, 3000);// if you have defined a function named myFunction it will run after 3 seconds (3000 milliseconds)

You can see a really good explanation of how to delay your code here : see the SolutionYogi response

Community
  • 1
  • 1
Sylv21
  • 345
  • 2
  • 11
-1
onclick="setTimeout(list_activity(), 2000);"