Mega,
quite a few problems with the code, have modified it slightly, give this a go...
<html>
<head>
<title>Development of an ASP/
JS watch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--//
// make the watch a global object
var gWatch;
function Watch(pName, pTargetTagId, pHour, pMinute, pSecond){
// set properties for this instance of the watch, not prototypes
this.Hour = pHour;
this.Second = pSecond;
this.Minute = pMinute;
this.Name = pName; // store global name of watch so we can set intervals for function calls
this.Target = document.getElementById(pTargetTagId); // locate div to display time in
this.Timer = null; // store handle to interval here so we can stop if we want
}
Watch.prototype.Start = function(){
if(this.Timer == null){
this.Timer = setInterval(this.Name + ".Tick();", 1000);
}
};
Watch.prototype.Stop = function(){
clearInterval(this.Timer);
this.Timer = null;
};
Watch.prototype.Tick = function(){
with(this){
Second++;
if(Second == 60){
Second = 0;
Minute++;
}
if(Minute == 60){
Minute = 0;
Hour++;
}
if(Hour == 24){
Hour = 0;
}
}
this.Target.innerHTML = this.GetTimeString();
};
Watch.prototype.GetTimeString = function(){
// when building string version, do not assign values to objects hour, minute, second properties
// - otherwise they get concatenated & will become 000000n etc
var temp = "";
with(this){
if(Hour < 10){
temp += '0';
}
temp += Hour + ":";
if(Minute < 10){
temp += '0';
}
temp += Minute + ":";
if(Second < 10){
temp += '0';
}
temp += Second;
}
return temp;
};
function startWatch(){
// create a new instance of the watch object, assign hour minute second here as well
// that way we can have more than one watch with different times
gWatch = new Watch("gWatch", "showTime", <%= Hour(Now) %>, <%= Minute(Now) %>, <%= Second(Now) %>);
gWatch.Start();
}
//-->
</script>
</head>
<body onload="startWatch();">
Klokken er <div id="showTime"></div>
</body>
</html>
HTH,
Chris