Why can't I dynamically pass a var into this function?




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> .



Relevant Pages

  • Var Assignment.
    ... I have a var in a javascript like so: ...
    (microsoft.public.inetserver.asp.general)
  • Var assignment in ASP Page
    ... I have a var in a javascript like so: ...
    (microsoft.public.vstudio.general)
  • Re: Anticipated Finish Variance
    ... make sure you delay any incomplete work to the date it will restart. ... With a baseline the finish variance should calculate as you go, no need to wait for an actual finish date. ... A client has asked if an anticipated finish var. ... Many Thanks - Luca ...
    (microsoft.public.project)
  • Re: Anticipated Finish Variance
    ... When MSP calculates Finish Variance it compares that date to the Baseline ... The problem is that my programme won't update the finish var. ... "Rod Gill" wrote: ... make sure you delay any incomplete work to ...
    (microsoft.public.project)
  • Re: Need Help Creating an Image Slideshow
    ... the same frame after a delay of some seconds. ... Wait xx seconds (different interval for each picture) ... var t = 0; ... consider using a slideshow object in the first place. ...
    (comp.lang.javascript)