User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,428 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,595 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1295 | Replies: 2
Reply
Join Date: Oct 2005
Location: Northampton UK
Posts: 1,142
Reputation: roryt will become famous soon enough roryt will become famous soon enough 
Rep Power: 7
Solved Threads: 9
roryt's Avatar
roryt roryt is offline Offline
Veteran Poster

Really simple script request - Count from 6 - 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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Really simple script request - Count from 6 - 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.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Oct 2005
Location: Northampton UK
Posts: 1,142
Reputation: roryt will become famous soon enough roryt will become famous soon enough 
Rep Power: 7
Solved Threads: 9
roryt's Avatar
roryt roryt is offline Offline
Veteran Poster

Re: Really simple script request - Count from 6 - 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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC