C
CES
All,
I have absolutely no clue as to what the difference is between these two snippets but the on that is hard coded works and the other doesn't. I know it's something incredible stupid that I should know but I just cant see it.
//This works if it's hard coded:
function setTimer(id,status){
if(status=="start"){
txt = new timer('txt',id);
txt.startTimer();
}else if(typeof txt == "object"){
txt.stopTimer();
txt = '';
}
}
//This doesn't work
function setTimer(id,status){
var x = txt;
if(status=="start"){
x = new timer(x,id);
x.startTimer();
}else if(typeof txt == "object"){
x.stopTimer();
x = '';
}
}
Any help on this would be greatly appreciated. Thanks in advance. - CES
The rest of the page is as follows:
function timer(name,id){
var secs = 10;
var timerID = null;
var timerRunning = false;
var delay = 1000;
this.startTimer = function (){
this.stopTimer();
this.counterStatus();
}
this.stopTimer = function (){
if(timerRunning != null){
clearTimeout(timerID);
this.timerRunning = false;
secs = 10;
}
}
this.resetTimer = function (){
stopTimer();
}
this.counterStatus = function (){
if (secs==0){
this.stopTimer();
document.getElementById(id).style.backgroundColor = "Red";
}else{
secs = secs - 1;
timerRunning = true;
document.getElementById(id).innerHTML = secs;
timerID = self.setTimeout(name + ".counterStatus()", delay);
}
}
}
<div id="id_test" style="width:100px; height:100px; background-color:blue;" onmouseover="setTimer('','')" onmouseout="setTimer('id_test','start')">
</div>
I have absolutely no clue as to what the difference is between these two snippets but the on that is hard coded works and the other doesn't. I know it's something incredible stupid that I should know but I just cant see it.
//This works if it's hard coded:
function setTimer(id,status){
if(status=="start"){
txt = new timer('txt',id);
txt.startTimer();
}else if(typeof txt == "object"){
txt.stopTimer();
txt = '';
}
}
//This doesn't work
function setTimer(id,status){
var x = txt;
if(status=="start"){
x = new timer(x,id);
x.startTimer();
}else if(typeof txt == "object"){
x.stopTimer();
x = '';
}
}
Any help on this would be greatly appreciated. Thanks in advance. - CES
The rest of the page is as follows:
function timer(name,id){
var secs = 10;
var timerID = null;
var timerRunning = false;
var delay = 1000;
this.startTimer = function (){
this.stopTimer();
this.counterStatus();
}
this.stopTimer = function (){
if(timerRunning != null){
clearTimeout(timerID);
this.timerRunning = false;
secs = 10;
}
}
this.resetTimer = function (){
stopTimer();
}
this.counterStatus = function (){
if (secs==0){
this.stopTimer();
document.getElementById(id).style.backgroundColor = "Red";
}else{
secs = secs - 1;
timerRunning = true;
document.getElementById(id).innerHTML = secs;
timerID = self.setTimeout(name + ".counterStatus()", delay);
}
}
}
<div id="id_test" style="width:100px; height:100px; background-color:blue;" onmouseover="setTimer('','')" onmouseout="setTimer('id_test','start')">
</div>