Javascript Browser Window setTimeout() Method display a timed text

Introduction

Display a timed text.

Click on the button below. The input field will tell you when two, four, and six seconds have passed.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="timedText()">Display timed text</button>
<input type="text" id="txt">
<script>
function timedText() {//from   w  w w  .j av  a2s  . co m
  var x = document.getElementById("txt");
  setTimeout(function(){ x.value="2 seconds" }, 2000);
  setTimeout(function(){ x.value="4 seconds" }, 4000);
  setTimeout(function(){ x.value="6 seconds" }, 6000);
}
</script>

</body>
</html>



PreviousNext

Related