11Tami Posted November 3, 2006 Share Posted November 3, 2006 Hi can anyone tell me why the array doesn't start over when it gets to the end? Thank you very much. Tami<BODY onload="changelink();"><a href="#" id="url"></a>arr = new Array(["link name"],["http://www.google.com"],["another link name"],["http://www.yahoo.com"]);function changelink() {document.getElementById("url").href = arr[new Date().getSeconds()-1][0]; document.getElementById("url").innerHTML = arr[new Date().getSeconds()-2][0]; setTimeout('changelink()',1000);} Quote Link to comment Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 The end of what? Why should it start over? Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 5, 2006 Author Share Posted November 5, 2006 I have only two items in the array just as an example. If you try to run the script with 60 items for every second when it get to the 60th item it stops. Its supposed to start over when it gets to the end of the array and it doesn't. Can anyone help me fix it? Thank you very much. Tami Quote Link to comment Share on other sites More sharing options...
fenway Posted November 5, 2006 Share Posted November 5, 2006 I don't see any looping in this code -- but I suppose you could use " % arr.length " in your array indicies. Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 5, 2006 Share Posted November 5, 2006 Sounds to me like what you really want is setInterval rather than setTimeout, since the latter will only run once. Also, assuming that's the same order you have the array in the actual script[code]document.getElementById("url").href = arr[new Date().getSeconds()][1]; document.getElementById("url").innerHTML = arr[new Date().getSeconds()][0];[/code]should give you the right items. new Date().getSeconds()-1 and 2 is going to kill everything with an error at 0 and 1 seconds.Hope that's what you need, I'm new here since I'm finally just starting to attempt learning some PHP, but I think I'm alright at the client-side stuff. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 6, 2006 Share Posted November 6, 2006 The setTimeout runs after each function call, so that's ok -- but I still don't see where the looping is. Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 7, 2006 Share Posted November 7, 2006 I realize there's no JavaScript loop so I'm taking it in a more figurative sense. ;)(Edit: D'oh now I see what you mean fenway, what in the world is wrong with me lol) Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 7, 2006 Author Share Posted November 7, 2006 Man you both make a great team and are both very nice, I appreciate the help. The looping only meant when it got to the end of the array it wouldn't start over but now it does. Between the two of your ideas it is almost working. Tele's adjusting my string, and keeping setTimeout like Fenway said, the two combinations work very well together. Now I am having trouble with my array, it was incorrect before it wasn't combining the two sides. I tried this but somethings still wrong, can you see what it is? Then I'll send you both something for helping me. Problem still with this, can't see a problem but there is one.arr = new Array[ ["Link name google","http://www.google.com"], ["Link name two","http://www.yahoo.com"] ]; Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 7, 2006 Share Posted November 7, 2006 Either use var arr = new Array(["Link name one","ht[i][/i]tp://www.google.com"]); or var arr = [["Link name two,"ht[i][/i]tp://www.google.com"]]; rather than the syntax you just posted. Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 7, 2006 Author Share Posted November 7, 2006 Gosh none of those work, seems like they should. You sure there isn't some sort of hidden conflict in this somewhere? -----> arrarr = new Array( ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"] ); arr = [ ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"]]; Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 Those posted code snippets should be just fine... Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 7, 2006 Share Posted November 7, 2006 Through the magic of copying and pasting twenty times I have it ticking away right now, but being half asleep as usual I forgot to to remove the comma at the end of the array lol and that little typo took me about twenty minutes to figure out. I'm betting it's something similar that's the only problem now. Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 7, 2006 Author Share Posted November 7, 2006 Man I would think so too, looks fine but somethings wrong. Commas all look correct. Strange thing is when I put in an incorrect array like this in it works.arr = new Array(["link name"],["http://www.google.com"],["another link name"],["http://www.yahoo.com"]);When I switch the above to a correct array like that below then it doesn't work. I don't get it. If anyone that knows javascript and has the time and can test it maybe you can see whats wrong. Here's the whole thing as it seems like it should work. <body onload="changelink()"><a href="#" id="url"></a> arr = new Array( ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"] ); function changelink() {document.getElementById("url").href = arr[new Date().getSeconds()][1]; document.getElementById("url").innerHTML = arr[new Date().getSeconds()][0];setTimeout('changelink()',1000);} Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 7, 2006 Share Posted November 7, 2006 I'm using this in script tags the head and I get no problems: [code]arr = new Array( ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"], ["Link name google","http://www.google.com"], ["Link name yahoo","http://www.yahoo.com"], ["Link name msn","http://www.msn.com"]);function changelink(){document.getElementById("url").href = arr[new Date().getSeconds()][1]; document.getElementById("url").innerHTML = arr[new Date().getSeconds()][0]; setTimeout('changelink()',1000);}[/code]And this inside the body:[code]<a href="#" id="url"></a> [/code]It works just fine for me in several browsers so personally I have no idea what else to say. ??? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 I'm confused... what's the issue now? Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 7, 2006 Author Share Posted November 7, 2006 LOL Fenway, have me giggling over here, your funny. Well thats a relief that made no sense. Thanks a lot Tel. Every many many months, things like this happen for no apparant reason. Last night I restarted the computer for another reason and its working fine now. I don't think my script was resaving properly. You guys did it! Thanks for help. I'll send you something at least. Quote Link to comment Share on other sites More sharing options...
11Tami Posted November 7, 2006 Author Share Posted November 7, 2006 ???OK whats wrong with the personal message function. This forums personal messages don't work. Can anyone try it and see if yours works? I am getting a gateway message. Try sending one to me if you need to test it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.