user61092
user61092

Reputation: 146

How to open a modal pop up after timer runs out?

I am a beginner in JavaScript and writing js code for a web application but stuck at one point.

I have a web page with a timer for 5 seconds and after the timer runs out I expect a modal to popup.

I have written the code here:

var count=-1; // initially -1 as we are having a delay of 1000ms

var counter=setInterval(timer, 1000); //1000 will  run it every 1 second

function timer()
{
    count=count+1;
    if (count >=6) //+1 than the req time as we have a delay of 1000ms
    {
        clearInterval(counter);
        /////////////what code should go here for the modal to pop up??///////////////////////
        return;
    }
    document.getElementById("timer").innerHTML=count + " secs"; // watch for spelling
}

I just want to know the code to enable the pop up after the timer runs out.

Upvotes: 1

Views: 4450

Answers (1)

Ava
Ava

Reputation: 2429

All you need to do is select the modal (with jQuery) and call its modal() method:

$("#myModal").modal();

That will invoke the modal. I've also modified your Fiddle to give you an example here: JSFiddle Example.

Upvotes: 3

Related Questions