472,143 Members | 1,143 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Trying to create a ticker with javascript -browser hangs

I have created a small page using html and javascript that attempts to create a ticker. I am trying to go from 0 to 9 and then repeat itself. It should go to each new value after 1 second.

Unfortunately, it simply displays 0 and hangs (shows hourglass in browser).

I am running my page on XP Professional, using javacript.

Code is as follows:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var x = 0;
  3. function ticker()
  4. {
  5. document.write(x);
  6. x++;
  7. if ( x == 9 )
  8. {
  9. x = 0;
  10. }
  11. }
  12. function cinterval()
  13. {
  14. setInterval(function() { ctick(); }, 1000);
  15. }
  16. function ctick()
  17. {
  18. cinterval();
  19. ticker();
  20. }
  21. </script>
  22. </head>
  23. <body onload="cinterval();">
  24.  
I appreciate any help that I hope to receive.
Sep 8 '07 #1
1 1315
pbmods
5,821 Expert 4TB
Heya, Murray.

You're using setInterval(), which automatically keeps iterating. You're thinking of setTimeout(), which only fires once.
Sep 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by dthelwal | last post: by
3 posts views Thread by Dan | last post: by
1 post views Thread by Kaz | last post: by
2 posts views Thread by alex.zeta | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.