Article directory - Natwest Credit Card - Turquoise Rings - Top Game Tips - Debt Consolidation

PDA

View Full Version : Javascript calling on a url?


Jen-
Aug 28th 2006, 2:03 am
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

phper
Aug 28th 2006, 5:10 pm
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]));

Jen-
Sep 2nd 2006, 4:00 am
Haven't had a chance to try this yet but thanks phper, I will soon

Jen-
Sep 2nd 2006, 4:38 am
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-

angellica2017
Sep 7th 2006, 10:42 pm
Thanks.... guys... it's make life easier!