Javascript calling on a url?

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

  1. #1
    Hello, I am trying to call on javascript to insert a url address into another page which changes daily. Here is what I have connected by a external .js link.

    arr = new Array(
    ["http://www.website.com/test.html"],
    ["http://www.mooonbaby.com/test2.php"]

    now = new Date()
    nowDate = now.getDate()

    function changeurl(){

    if(nowDate > arr.length) { return; }

    document.getElementById("url").href = arr[nowDate-1][0];
    }

    ___________________________________________________________
    And this goes in the body.

    <p style="margin-left: 0px;"><BODY onload="changeurl();">

    <a href="#"><id="url"></a></p>

    Can anyone see why it doesn't work? Is it because the href usually deals with links only and images? Thanks!! Jen
     
    Jen-, Aug 28, 2006 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Change this:
    <a href="#"><id="url"></a>

    to this:
    <a href="#" id="url"></a>


    And after this line:
    document.getElementById("url").href = arr[nowDate-1][0];

    add this:
    document.getElementById("url").appendChild(document.createTextNode(arr[nowDate-1][0]));
     
    phper, Aug 28, 2006 IP
  3. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Haven't had a chance to try this yet but thanks phper, I will soon
     
    Jen-, Sep 2, 2006 IP
  4. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Was able to test it faster than I thought. It works great phper!!! But not for what I needed. But I may need that someday anyway thank you very much. But what I was looking for was rotating an actual url and inserting that into another page, not a link. Don't write anything for rotating urls with an Iframe though, I already have one of those. Was looking to see if there was a way javascript could insert the url without using an iframe. If you think of a way let me know, otherwise don't sweat it and thanks again. Jen-
     
    Jen-, Sep 2, 2006 IP
  5. angellica2017

    angellica2017 Peon

    Messages:
    351
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks.... guys... it's make life easier!
     
    angellica2017, Sep 7, 2006 IP