Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- getting a global variable to update every setInterval call


shingokko - 12:35 pm on May 4, 2012 (gmt 0)


var t=setInterval(clock(time,play),1000)

What you are doing here is calling the function 'clock(time,play)' and setting the callback function of setInterval to the result, which is 'undefined'. You should change it to:

var t = setInterval(function() { clock(time,play); }, 1000);

Also I want to point out that:

- you should declare the variables of the same name once to avoid confusion at least in your code, for example, you are declaring the variable 'time' twice.

var time = 30;

// your functions

var time = 30; // <= no point doing this

Also the parameters of some of your functions are the same as some of the global variables you've already declared. You should change them so that it's clear wherher you are setting the value of global or local variables.

Good luck!


Thread source:: http://www.webmasterworld.com/javascript/4449318.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com