Could use some help with a link problem.

A

Amy

Hello this script was switched to one with a timer. But now it doesn't
work right. The items in the left are supposed to be the link names,
and the items in the right are supposed to be the link addresses. When
it was switched from a day rotation to a timed rotation something is
keeping it from working as a link. Can anyone see why? Please let me
know, thanks, Amy
one that works by day just following and works correctly. <BODY
onload="changelink();"><a href="#" id="url"></a>

var arr = [
["Link name google web site"],["http://www.google.com"],
["two link"],["http://www.yahoo.com"]
];

now = new Date();
nowDate = now.getDate();
function changelink(){
if (nowDate*2 > arr.length) return;
document.getElementById("url").href = arr[nowDate*2-1][0];
document.getElementById("url").appendChild(document.createTextNode(arr[nowDate*2-2][0]));
}


The following works by milliseconds. It only switches from the left
item to the right item
but left item isn't a link to the right item like it is supposed to be.
Can anyone help me fix it? Thank you very much. <BODY
onload="changelink();"><a href="#" id="url"></a>


var arr = [
["Link name google web site"],["http://www.google.com"],
["two link"],["http://www.yahoo.com"]
];
var dynLink = null;

function init() {
dynLink = document.getElementById('url');
window.setTimeout('changeURL(0)',1000);
}

function changeURL(i) {
if (i >= arr.length) {
i = 0;
}
dynLink.innerHTML = arr[0];
dynLink.href = arr[1];
window.setTimeout('changeURL('+(++i)+')',1000);
}
window.onload = init;
 
L

Lee

Amy said:
Hello this script was switched to one with a timer. But now it doesn't
work right. The items in the left are supposed to be the link names,
and the items in the right are supposed to be the link addresses. When
it was switched from a day rotation to a timed rotation something is
keeping it from working as a link. Can anyone see why?
var arr = [
["Link name google web site"],["http://www.google.com"],
["two link"],["http://www.yahoo.com"]
];
function changeURL(i) {
if (i >= arr.length) {
i = 0;
}
dynLink.innerHTML = arr[0];
dynLink.href = arr[1];
window.setTimeout('changeURL('+(++i)+')',1000);
}
window.onload = init;


Ask your instructor to explain arrays more clearly.
You don't seem to understand what these mean:
arr[0]
arr[1]


--
 
A

Amy

Can't you just tell me what you're trying to say, many of us don't have
instructors, I did a google search and I still don't know how to fix
it.
Lee said:
Amy said:
Hello this script was switched to one with a timer. But now it doesn't
work right. The items in the left are supposed to be the link names,
and the items in the right are supposed to be the link addresses. When
it was switched from a day rotation to a timed rotation something is
keeping it from working as a link. Can anyone see why?
var arr = [
["Link name google web site"],["http://www.google.com"],
["two link"],["http://www.yahoo.com"]
];
function changeURL(i) {
if (i >= arr.length) {
i = 0;
}
dynLink.innerHTML = arr[0];
dynLink.href = arr[1];
window.setTimeout('changeURL('+(++i)+')',1000);
}
window.onload = init;


Ask your instructor to explain arrays more clearly.
You don't seem to understand what these mean:
arr[0]
arr[1]


--
 
A

ASM

Amy a écrit :
Can't you just tell me what you're trying to say, many of us don't have
instructors, I did a google search and I still don't know how to fix
it.

ask to google : javascript array two dimensions

var arr = [
[["Link name google web site"],["http://www.google.com"]],
[["two link"],["http://www.yahoo.com"]]
];
function changeURL(i) {
if (i >= arr.length) {
i = 0;
}
dynLink.innerHTML = arr[0];
dynLink.href = arr[1];
window.setTimeout('changeURL('+(++i)+')',1000);
}
window.onload = init;

Ask your instructor to explain arrays more clearly.
You don't seem to understand what these mean:
arr[0]
arr[1]


--

 
R

RobG

Amy said:
Hello this script was switched to one with a timer. But now it doesn't
work right. The items in the left are supposed to be the link names,
and the items in the right are supposed to be the link addresses. When
it was switched from a day rotation to a timed rotation something is
keeping it from working as a link. Can anyone see why? Please let me
know, thanks, Amy
one that works by day just following and works correctly. <BODY
onload="changelink();"><a href="#" id="url"></a>

var arr = [
["Link name google web site"],["http://www.google.com"],
["two link"],["http://www.yahoo.com"]
];

Your code wants an array of arrays, make the above an array by removing
the inner brackets (untested, but if the rest works...):

var arr = [
["Link name google web site","http://www.google.com"],
["two link","http://www.yahoo.com"]
];
 
A

ASM

A

Amy

I had to leave the other thread because my code wasn't working.

Thank you very much ASM for helping me, very much appreciated. Anywhere
I can send you some stuff? Amy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top