D
D
dev4002016-03-18 21:27:48
JavaScript
dev400, 2016-03-18 21:27:48

How to do this in javascript?

When the form is submitted (in a Bootstrap modal window), a countdown counter should appear (let's say 30 seconds) and after that a certain caption should appear. Can you please tell me how this can be done? (at least approximately, I just don’t understand much in js)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FMars, 2016-03-19
@dev400

Use a function setInterval: https://jsfiddle.net/j29pf67j/1/

var counter = document.getElementById("counter")
var hiddenText = document.getElementById("hidden-text")
var run = function(seconds) {
  var interval = setInterval(function(){
    if (seconds > 0) {
      counter.textContent = seconds--;
    }
    else 
    {
      hiddenText.style.display = "block";
      counter.style.display = "none";
      clearInterval(interval);
    }
  }, 1000)
}

S
Super User, 2016-03-18
@sergeystepanov1988

function showMessage(){
  alert('Done');
}
setTimeout(showMessage, 30000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question