By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

On Time

100+
P: 129
Hello friends,
I am writing while function in javascript, when some condition equals i want to wait execution for some time of seconds. How to do that?
I searched internet for sleep or wait method but they telling that there is no sleep or wait methods in javascript.

So please help me, with some code if possible.......................
Sep 23 '08 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
Use setTimeout or setInterval.
Sep 23 '08 #2

RamananKalirajan
100+
P: 607
[HTML]<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+" :"+s;
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>[/HTML]

With the use of setTimeout() I am refreshing the page and displaying the time every .5sec so that it seems to be dynamic clock for the users.

Regards
Ramanan Kalirajan
Sep 23 '08 #3

100+
P: 129
Hi friend,
very very thanks for coding. It is very much useful to me. Thanks once again.
Sep 23 '08 #4

RamananKalirajan
100+
P: 607
Hi friend,
very very thanks for coding. It is very much useful to me. Thanks once again.
If any doubts in the future post it in the forum. I will try to help you out.

Regards
Ramanan Kalirajan
Sep 23 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.