Set time to execute Javascript function?

RobbertT

I have the following function hooked into my Wordpress plugin.

function before_submit() { 
    document.getElementById('page-loader').style.display='block';
}

This hook is being called before it submits a form. Now what i would like to do is to get the div id page-loader for a specific number of seconds, before it actually submits the form. I've read about the settimeout function and tried some stuff, but i cannot get it working. I guess the settimeout function is to run a script after a certain number of seconds instead of running it for a number of seconds correct?

So i'd like the script to have a 'running time' of, for instance, 4 seconds. Now it runs the script and submits the form immidiately

Tried this but it's not working:

function before_submit()
{

function partA() {
document.getElementById('page-loader').style.display='block';
  window.setTimeout(partB,1000)
}

function partB() {
//let's go submit the form
}
}

Please help me out. Thank you so much!

Jared Farrish

This is the format you're looking for:

// Note, in the fiddle, this is run during the window.onload event.
var test = document.getElementById('test');

test.addEventListener('submit', function before_submit(e){
    document.getElementById('wait').style.display = 'block';

    setTimeout(function wait(){
        // After waiting for five seconds, submit the form.
        test.submit();
    }, 5000);

    // Block the form from submitting.
    e.preventDefault();
});

http://jsfiddle.net/rmef40c5/

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

set javascript time to a specific timestamp

분류에서Dev

Javascript/jQuery auto set and update time

분류에서Dev

Display automatically set to block in JavaScript function

분류에서Dev

Basic Javascript Countdown Timer Taking Longer Than Time Set

분류에서Dev

using a function no more then 1 time in 2 sec in javascript

분류에서Dev

execute a function if something is not fulfilled

분류에서Dev

NodeJS function execute order

분류에서Dev

Execute standard output with function

분류에서Dev

PostgreSQL function execute query

분류에서Dev

How to automatically execute a javascript function from an external js file on page load with a specific condition

분류에서Dev

Execute code every time the application begins

분류에서Dev

Execute compile time-compiled regex at compile time

분류에서Dev

PHP Time Zone Function

분류에서Dev

Time a function in erlang

분류에서Dev

Set Date Time to Jquery date time picker

분류에서Dev

How to set CORS of a public Google Cloud Storage buckets to avoid errors when using javascript fetch function?

분류에서Dev

Automatically set an updatedAt time on a record

분류에서Dev

Tracking elapsed time for a set of Tasks

분류에서Dev

Pass a function with a set argument

분류에서Dev

set variable to an instance of a function

분류에서Dev

Changing function code using a decorator and execute it with eval?

분류에서Dev

Azure function does not execute other Python functions

분류에서Dev

How to execute a function after scrolling (jquery)

분류에서Dev

Why the validation function doesn't execute

분류에서Dev

Javascript UNIX time conversion

분류에서Dev

JavaScript calculate time and seconds

분류에서Dev

How to execute JavaScript code in EJS template?

분류에서Dev

JavaScript library set this to an element

분류에서Dev

How does the srand function interact with time function?

Related 관련 기사

  1. 1

    set javascript time to a specific timestamp

  2. 2

    Javascript/jQuery auto set and update time

  3. 3

    Display automatically set to block in JavaScript function

  4. 4

    Basic Javascript Countdown Timer Taking Longer Than Time Set

  5. 5

    using a function no more then 1 time in 2 sec in javascript

  6. 6

    execute a function if something is not fulfilled

  7. 7

    NodeJS function execute order

  8. 8

    Execute standard output with function

  9. 9

    PostgreSQL function execute query

  10. 10

    How to automatically execute a javascript function from an external js file on page load with a specific condition

  11. 11

    Execute code every time the application begins

  12. 12

    Execute compile time-compiled regex at compile time

  13. 13

    PHP Time Zone Function

  14. 14

    Time a function in erlang

  15. 15

    Set Date Time to Jquery date time picker

  16. 16

    How to set CORS of a public Google Cloud Storage buckets to avoid errors when using javascript fetch function?

  17. 17

    Automatically set an updatedAt time on a record

  18. 18

    Tracking elapsed time for a set of Tasks

  19. 19

    Pass a function with a set argument

  20. 20

    set variable to an instance of a function

  21. 21

    Changing function code using a decorator and execute it with eval?

  22. 22

    Azure function does not execute other Python functions

  23. 23

    How to execute a function after scrolling (jquery)

  24. 24

    Why the validation function doesn't execute

  25. 25

    Javascript UNIX time conversion

  26. 26

    JavaScript calculate time and seconds

  27. 27

    How to execute JavaScript code in EJS template?

  28. 28

    JavaScript library set this to an element

  29. 29

    How does the srand function interact with time function?

뜨겁다태그

보관