How do I add a replace child to this please?

Discussion in 'JavaScript' started by Jen-, Oct 28, 2006.

  1. #1
    function changelink(){
    document.getElementById("url").href = arr[new Date().getSeconds()*2-1][0];
    document.getElementById("url").appendChild(document.createTextNode(arr[new Date().getSeconds()*2-2][0]));setTimeout('changelink()',1000);}

    Hi having a lot of trouble adding a replace child to the .appendChild .createTextNode after the middle of the above function

    Right now its stacking new text links instead of replacing the old one with the new one. Getting tired of reading up on it with no luck.

    Please let me know, thank you very much.
     
    Jen-, Oct 28, 2006 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    function changelink()
    	{
    	document.getElementById("url").href = arr[new Date().getSeconds()*2-1][0];
    	document.getElementById("url").innerHTML = arr[new Date().getSeconds()*2-2][0];
    	setTimeout('changelink();',1000);
    	}
    
    PHP:
    Try like that :)
     
    Morishani, Oct 28, 2006 IP
  3. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Morishani, thank you soooo much that was really gettin to me. That helped a lot, now the array won't start over when it gets to the end. Anyone know why? I added this to the end of the function with no luck. I need a better one. if (arr.length < 61)
    return arr;}
     
    Jen-, Oct 28, 2006 IP
  4. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What this function should be do anyway?
     
    Morishani, Oct 28, 2006 IP
  5. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have an array that has 60 items, with that function right under it. It supposed to change every second which it does now but when it gets to the end of the array the 60th item it stops. Doesn't start over.
     
    Jen-, Oct 28, 2006 IP
  6. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    function changelink()
    	{
    	document.getElementById("url").href = arr[(new Date().getSeconds()*2-1)%60][0];
    	document.getElementById("url").innerHTML = arr[(new Date().getSeconds()*2-2)%60][0];
    	setTimeout('changelink();',1000);
    	}
    
    PHP:
    Try like that :)
     
    Morishani, Oct 28, 2006 IP
  7. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Doesn't work but someone gave me something else by rewriting the whole thing, so if you can't come up with anything thats ok. If you ever think of another way to have the seconds reloop when they get to the end please let me know.
     
    Jen-, Oct 29, 2006 IP
  8. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Mmmm , lets try again :D
    
    var i = 0;
    function changelink()
    	{
    	document.getElementById("url").href = arr[i*2-1][0];
    	document.getElementById("url").innerHTML = arr[i*2-2][0];
    	setTimeout('changelink();',1000);
    	i++;
    	if (i>60) i=0;
    	}
    
    PHP:
    Try like that :)
     
    Morishani, Oct 29, 2006 IP
  9. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    No worky, but thats ok, Morishani, you've already helped a lot. Someone already gave me one for a generic time, was looking for something to change right on the second, then to start over. If anyone knows how to alter mine to do that please let me know.
     
    Jen-, Oct 30, 2006 IP