Hi all..

I am doing the display board for my company.
My problem is I don't have any idea how to count every minutes that given.
Like every 5 minutes it count 1 then 5 minutes later it count 2 until the certain time.
Can anyone give me some hint or example?
Thanks in advance.

Try using javascript setTimeout()

Can I possible to do the stop counting by itself then start back the counting automatically too?

Try searching for php Iteration or implementing IteratorAggregate in php. That should do it with switch function.

Then try setInterval(expression, interval) to start the timer and clearInterval(intervalID) to stop the timer.
seltInterval(expression, interval) invoke the given expression continuously with given time interval

var intervalID = seltInterval( "doSomething()", 5000 );

clearInterval(intervalID) clears the timer.

clearInterval(intervalID);

To start again call seltInterval again

Is it the seltInterval take the previous stop time or the current time in machine?

It will be a new timer

Hi..
I already have the counting code but it must click the start and stop function.
but the problem is I want the system run without need to click start and stop button. And also how can I set the time when it is start and when it is stop.

This is my code

count.php

<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",480000);
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
</head>

<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
</body>
</html>

Give it to the onload

<body onload="doTimer()">

It's work niranga!
How about the stop function?

When do you want to stop it? I mean on what condition?

Actually I want to set the time when it's start count and when it's stop counting.
Is it possible for me to do it?

You are saying, you have a fix duration and just after that time elapsed you want to stop the timer?

Yes definitely..

Then use a variable to hold the seconds you need to count and reduce it one by one until it reaches zero. Soon after it becomes zero call stopCount()

Can you give me some example?I can't get it.Sorry for your inconvenience.

function timedCount(){
	document.getElementById('txt').value=c;
	c=c+1;
	if(c == 5){
		c = 0;
		stopCount();
	}else{
		t=setTimeout("timedCount()",480000);
	}
}

Hi.
I already do this function.
Can you remark me where is the mistake?

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
if(c == 14){
		c = 0;
		continue();
	/*}else{*/
		t=setTimeout("timedCount()",1000);
	}

Hi.
I already do this function.
Can you remark me where is the mistake?

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
if(c == 14){
		c = 0;
		continue();
	/*}else{*/
		t=setTimeout("timedCount()",1000);
	}

you've commented out the else statement, c will not equal 14 at first so timeCount() will not be called again. It's there so timedCount() will keep running until c equals 14, once c equals 14 it sets c to 0 and runs a function called continue() and won't run timedCount() again

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
alert('timedCount called. c = '+c);
if(c == 14){
		c = 0;
		continue();
	}else{
		t=setTimeout("timedCount()",1000);
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.