odd bug setTimeout

Discussion in 'JavaScript' started by hip_hop_x, Dec 5, 2008.

  1. #1
    function timeout(x){
    document.getElementById(x).innerHTML="processing";
    setTimeout(document.getElementById(x).innerHTML="done",5000);
    }
    
    Code (markup):
    I've written this function, it should work fine, but there's a small problem, the setTimeout goes instantly. Instead of showing processing then after 5 seconds to show done, it directly displays done. Anyone knows how to fix this kind of problem?
     
    hip_hop_x, Dec 5, 2008 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    not tested but...
    var beingDone, doneMessage = function(), {
        beingDone.innerHTML = 'done';
    }, timeout = function(x) {
        beingDone = document.getElementById(x);
        beingDone.innerHTML = "processing";
        setTimeout(doneMessage, 5000);
    };
    
    timeout("mydiv"); // call it.
    
    PHP:

    you _should_ also be able to modify what you wrote in a way that works by using " " around code that it needs to evaluate but escaped it well for strings slashes etc.
     
    dimitar christoff, Dec 5, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    function timeout(x)
    {
    	document.getElementById(x).innerHTML = "processing";
    	setTimeout(function(){
    		document.getElementById(x).innerHTML = "done";
    	}, 5000);
    }
    Code (markup):
     
    joebert, Dec 6, 2008 IP
  4. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #4
    thank you, it works great.
     
    hip_hop_x, Dec 6, 2008 IP