Jump to content

[SOLVED] Counter


rugzo

Recommended Posts

Hi All,

 

i have a code which shows the clock. But i want to use it as a counter like a kronometre. It simply will start to count from zero if the page is refreshed. That i managed but i couldn't make it to count from zero.

I know that something like below

 

x = new date() ; y = new date(), start = x - y... but couldn't do it since my java knowledge is not enough. I will implement this into my php page. Can someone please help. It just has to start from 00:00:00

 

 

 

<html>

<head>

<script language="JavaScript">

 

<!--

 

 

var clockID = 0;

 

function UpdateClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

 

var tDate = new Date();

 

if((tDate.getSeconds())<=9)

{

document.theClock.theTime.value = ""

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

} else if((tDate.getMinutes())<=9) {

document.theClock.theTime.value = ""

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

} else if(((tDate.getSeconds())<=9) && ((tDate.getMinutes())<=9)) {

document.theClock.theTime.value = ""

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":0"

+ tDate.getMinutes() + ":0"

+ tDate.getSeconds();

} else {

 

 

document.theClock.theTime.value = ""

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

document.title = "The time is: "

+ tDate.getHours() + ":"

+ tDate.getMinutes() + ":"

+ tDate.getSeconds();

}

 

clockID = setTimeout("UpdateClock()", 1000);

}

function StartClock() {

clockID = setTimeout("UpdateClock()", 500);

}

 

function KillClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

}

 

//-->

 

</script>

</head>

<body onload="StartClock()" onunload="KillClock()">

<center>

<form name="theClock"><input name="theTime" size="8" type="text">

</form>

</center>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/169204-solved-counter/
Share on other sites

ok i got it :)

 

<code><html>

<head>

<script language="JavaScript">

 

<!--

 

 

var clockID = 0;

var saniye = 00;

var dakika = 00;

var saat = 00;

 

function UpdateClock() {

 

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

 

saniye ++;

if(saniye <= 9)

{

var saniye_yaz = "0" + saniye ;

}else{

var saniye_yaz = saniye ;

}

 

if (saniye > 59)

{

dakika ++;

saniye = 0;

saniye_yaz ="00";

}

 

if(dakika <=9)

{

var dakika_yaz = "0" + dakika ;

}else{

var dakika_yaz = dakika ;

}

 

 

 

if(dakika > 59)

{

saat ++;

dakika = 0;

dakika_yaz = "00";

}

 

if(saat <=9)

{

var saat_yaz = "0" + saat ;

}else{

var saat_yaz = saat ;

}

 

if(saat>=24)

{

saat=0;

dakika=0;

saniye=0;

}

document.theClock.theTime.value = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

document.title = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

clockID = setTimeout("UpdateClock()", 1000);

}

 

 

function StartClock() {

clockID = setTimeout("UpdateClock()", 500);

}

 

function KillClock() {

if(clockID) {

clearTimeout(clockID);

clockID = 0;

}

}

 

//-->

 

</script>

</head>

<body onLoad="StartClock()" onUnload="KillClock()">

<center>

<form name="theClock"><input name="theTime" size="8" type="text">

</form>

</center>

</body>

</html></code>

 

Link to comment
https://forums.phpfreaks.com/topic/169204-solved-counter/#findComment-893515
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.