Wrox Programmer Forums
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 19th, 2012, 03:43 PM
Registered User
Join Date: Jul 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default setInterval question

I want the following code to execute a specified number of times at intervals of one second. Currently, it continues running indefinitely. Can anyone tell me what I'm doing wrong?

function clickHandler() {
            var passes = 0;
            var interval = setInterval(someMethod, 1);
            function someMethod() {
                if (passes > 199) {
Thanks in advance for any responses.
Old October 21st, 2012, 01:27 PM
Friend of Wrox
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts

Hi SillyPants,

You've got too many closing brackets (}) in your code snippet.

Once you've fixed that up, try to work out what the scope of your passes variable is, i.e. is it global to the page or restricted to one object/function.

The Following User Says Thank You to philip_cole For This Useful Post:
SillyPants (October 22nd, 2012)

Similar Threads
Thread Thread Starter Forum Replies Last Post
ch 10 Banner Advertisement, setInterval socosean BOOK: Beginning JavaScript 4th Edition 0 October 11th, 2011 10:46 AM
Disappearing UserName & Question within Customized PasswordRecovery Question Template eddiemcham ASP.NET 3.5 Basics 13 June 13th, 2009 04:23 AM
Does SetInterval spawn many threads? pigtail Javascript 0 April 10th, 2004 11:39 PM
Can I use SetInterval to refresh recordset? pigtail Javascript 4 April 10th, 2004 11:09 PM
Can I use setInterval to refresh recordset?? pigtail Javascript How-To 1 April 10th, 2004 08:12 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.