469,645 Members | 1,193 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

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 1256
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 gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.