setTimeout in Javascript (24 th April 2022 : Sunday Class)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>use of array</title>
<script src="myscript.js"></script>
<script>
var str="compuhelp";
var ctr=-1;
var mytimer;
function getInput()
{
//str=prompt("Enter string :");
//alert("your string is " + str);
// document.write(str);
if(ctr<str.length-1)
{
ctr++;
para1.innerHTML=para1.innerHTML + str.charAt(ctr);
}
else{
para1.innerHTML="";
ctr=-1;
}
mytimer=setTimeout(getInput,1000);
}
function stop(x)
{
if(x.value=="Start")
{
mytimer=setTimeout(getInput,1000);
x.value="Stop";
}
else
{
x.value="Start";
clearTimeout(mytimer);
}
}
</script>
</head>
<body>
<h1 id="head1" onclick="getInput()">Use of Array</h1>
<p id="para1"></p>
<div>
<input type="button" value="use Array" onclick="useArray()"/>
<input type="button" value="Start" onclick="stop(this)"/>
</div>
</body>
</html>
Comments
Post a Comment