Really simple script request - Count from 6 - 0

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Oct 2005
Posts: 1,283
Reputation: roryt will become famous soon enough roryt will become famous soon enough 
Solved Threads: 14
roryt's Avatar
roryt roryt is offline Offline
Nearly a Posting Virtuoso

Really simple script request - Count from 6 - 0

 
0
  #1
Jun 5th, 2007
I have looked high and low for a very simple script that i can use to display on a page from 6 down to 1.

Basically it should start like this:

"this page will redirect in 6 seconds"

and end like this:

"this page will redirect in 0 seconds"

I know exactly the type of people on this forum and how clever you are so if you could please just help me out, I will be really really grateful.

Thanks
PhotoShopthis
FlyingPen
If I have helped you please add to my reputation
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Really simple script request - Count from 6 - 0

 
0
  #2
Jun 6th, 2007
Normally such a thing is almost always done using a server side script (you know why), but since you have been nice in your conduct on Daniweb, I would try something out for you.

How about something like:
  1. <!--
  2. author: Sanjay aka ~s.o.s~
  3. A simple redirection script which runs on the client side.
  4. -->
  5. <html>
  6. <head>
  7. <style>
  8. .myDiv
  9. {
  10. text-align: center;
  11. font: italic small-caps 900 14px arial
  12. }
  13. </style>
  14. <script>
  15. var count = 5;
  16. var timerHandle;
  17. var URL = "[URL]http://www.yahoo.com[/URL]";
  18. var SITE_NAME = "Yahoo";
  19.  
  20. function startCountDown()
  21. {
  22. update();
  23. timerHandle = setInterval("update()", 1000);
  24. }
  25.  
  26. function update()
  27. {
  28. if(count <= 0)
  29. {
  30. clearInterval(timerHandle);
  31. document.getElementById('txt').innerHTML = 'Redirecting, please wait...';
  32. window.location.assign(URL);
  33. /*
  34.   You can also use the window.location.replace() function with the difference
  35.   being you won't be able to hit the back button once the new page has been
  36.   loaded. Use the function which suits your purpose
  37.   */
  38. }
  39. else
  40. {
  41. //you can also embed the entire message in a 'anchor' tag so that the user can decide not to
  42. //wait and click on the link to go to the site.
  43. document.getElementById('txt').innerHTML = 'You would be redirected to '+ SITE_NAME + ' in ' + count + ' seconds.';
  44. --count;
  45. }
  46. }
  47.  
  48. </script>
  49. </head>
  50. <body onload="javascript:startCountDown();">
  51. <br /><br /><br />
  52. <div class="myDiv" id="txt"></div>
  53. </body>
  54. </html>

Just let me know if it works for your cause. ;-)
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 1,283
Reputation: roryt will become famous soon enough roryt will become famous soon enough 
Solved Threads: 14
roryt's Avatar
roryt roryt is offline Offline
Nearly a Posting Virtuoso

Re: Really simple script request - Count from 6 - 0

 
0
  #3
Jun 8th, 2007
Really sorry to put your through that. I actually dont thank you for it and I am sure other will find it useful.

I have done the redirect in php.

All I wanted to know was how to just simply count from 6 down to 1 in javascript. It really is probably a 2 line code.

Thanks for your help
PhotoShopthis
FlyingPen
If I have helped you please add to my reputation
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC