1

I want to make an alert that has a timer in it, the alert will show this message:

Please wait to process data 3 second..

Please wait to process data 2 second..

Please wait to process data 1 second..

and if the timer is done, the text will change to:

Succesfully process data..

I tried this one:

function countdown() {
    var seconds = 3;
    function tick() {
        var counter = document.getElementById("counter");
        seconds--;
        counter.innerHTML = "Please wait to process data " + String(seconds)+ " Second";
        if( seconds > 0 ) {
            setTimeout(tick, 1000);
        } else {
            alert("Succesfully process data");
        }
    }
    tick();
}

countdown();

<div id="results"></div>
<button id="stop">Stop</button>

but this code will show the timer in div, not in alert. I tried to edit to make it show in alert but still can not figure it out.

2
  • 2
    I believe this to be a duplicate of Display dynamic values in javascript alertbox. If this is incorrect, please specify how it differs to better aid the community in answering your question. Good luck, and happy coding! Commented Mar 1, 2022 at 4:57
  • 1
    Also, for what it is worth, I believe that ultimately the answer to this is that it is not possible. You can look at the MDN window.alert() reference page to see no such functionality is exposed. Commented Mar 1, 2022 at 5:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.