dodgeitorelse Posted August 23, 2011 Share Posted August 23, 2011 Hi, is it possible to change a text string after a 5 second period? What i want is text string "A" to display on page, then after five seconds replace text string "A" with text string "B" then after another 5 seconds replace with text string "C" then after 5 seconds display text string "A" again and keep doing this? Quote Link to comment Share on other sites More sharing options...
nogray Posted August 23, 2011 Share Posted August 23, 2011 look up setTimeout and setInterval Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 23, 2011 Author Share Posted August 23, 2011 ok ty  Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 23, 2011 Share Posted August 23, 2011 [Moved to JavaScript forum] Â You will need to accomplish this using JavaScript. How many strings do you have? If you only have a relatively small number then just create the text strings as JavaScript values (in an array). If it is an excessively large number then you would use AJAX (JavaScript + PHP, or some other server-side technology) to get them from the server. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 23, 2011 Author Share Posted August 23, 2011 Ok, I am working on that. I have 3 strings. But some code I found in a tutorial is making me click a button to activate the timer and I don't want a timer so I am still looking into it. By the way thanks for moving my post to the proper section. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 24, 2011 Share Posted August 24, 2011 You will want to create a function that is run "onload" of the page. That function should get the next line of text to display and populate a div with that content (hint, "innerHTML"). Then at the end of the function you would use settimeout() to call the function again (i.e. make it recursive) after 5 seconds. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 24, 2011 Author Share Posted August 24, 2011 Ok, again ty, will let you know my results Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 25, 2011 Author Share Posted August 25, 2011 ok so far I have this which does display my messages (3 of them) using  <script type="text/javascript"> var customMessages = Array('Click \"Image\" to see server details....', 'Click \"Map Name\" to go directly to download link for that map....', 'Click \"Player Scores\" to see top 10 players for that server'); var secondsPassed = 0; function show_notes() { var t = setTimeout("load()", 3000); } function load() { document.getElementById("tracker_notes").style.color = "red"; document.getElementById("tracker_notes").innerHTML = customMessages[secondsPassed]; if(++secondsPassed < 6) var t = setTimeout("load()", 4000); else document.getElementById("tracker_notes").innerHTML = ''; } </script>  however at the end of the third code it then displays "undefined as if it were another message. I can't for the life of me see what is undefined.  I am also working on getting this function to keep reloading so that it repeats the 3 messages over and over. Am I going in the right direction or am I way off here? Quote Link to comment Share on other sites More sharing options...
nogray Posted August 26, 2011 Share Posted August 26, 2011 You are in the right direction. You are getting undefined because your array has 3 values and you are trying to get 6 values. Change your if statment as the following // change this if(++secondsPassed < 6) // to this if(++secondsPassed < customMessages.length) Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 26, 2011 Author Share Posted August 26, 2011 thank you nogray, that helped but was still not showing last value in array. I fixed that by add 2 singles quotes at end of array. I also have a value in the else statement. So now I have to figure out the part to make it all loop. Quote Link to comment Share on other sites More sharing options...
nogray Posted August 26, 2011 Share Posted August 26, 2011 If you want it to loop again, set the secondsPassed to 0 and set the timeout again. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse Posted August 26, 2011 Author Share Posted August 26, 2011 Thank you but after getting this code incorporated into the actual page it is going to be used on I realized that I don't need the loop feature as the page refreshes itself at 2 minute intervals. So having 18 values in the array it works out good. Thank you both for your help. 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.