W
Weston C
In the course of trying to build a simple clock, I've run into a problem
using the setInterval (and setTimeout) function.
http://weston.canncentral.org/misc/tkeep/tkeep.html
http://weston.canncentral.org/misc/tkeep/tkeep.jss
function fieldToClock(fieldId)
{
var field = document.getElementById(fieldId);
alert("Starting a clock in text field " + fieldId + "(" + field
+ ")");
codeSnippet = "clockUpdate(" + fieldId + ")";
setInterval(clockUpdate(fieldId),1000);
//setInterval(codeSnippet,1000);
//setInterval("eval(\"" + codeSnippet + "\")",1000);
}
function clockUpdate(fieldId)
{
field = document.getElementById(fieldId);
field.value = date2timestr(new Date());
}
The problem line is the setInterval line, and it seems to have something
to do with the fact I want to pass the function clockUpdate an argument
(I don't want to specify a single text element to be associated with the
display of the clock. Ideally, I'd like to be able to call the function
"fieldToClock" with the id of any text field in the document and turn it
into a clock).
The two commented out lines are other approaches I've applied. The first
approach yields the error:
Error: useless setInterval call (missing quotes around argument?)
Source File: http://weston.canncentral.org/misc/tkeep/tkeep.jss
Line: 6
The second/third approach yeild:
Error: clock_STF is not defined
Source File: http://weston.canncentral.org/misc/tkeep/tkeep.jss
Line: 7
Except this error is repeated every 1000 seconds.
Any ideas?
Thanks,
Weston
using the setInterval (and setTimeout) function.
http://weston.canncentral.org/misc/tkeep/tkeep.html
http://weston.canncentral.org/misc/tkeep/tkeep.jss
function fieldToClock(fieldId)
{
var field = document.getElementById(fieldId);
alert("Starting a clock in text field " + fieldId + "(" + field
+ ")");
codeSnippet = "clockUpdate(" + fieldId + ")";
setInterval(clockUpdate(fieldId),1000);
//setInterval(codeSnippet,1000);
//setInterval("eval(\"" + codeSnippet + "\")",1000);
}
function clockUpdate(fieldId)
{
field = document.getElementById(fieldId);
field.value = date2timestr(new Date());
}
The problem line is the setInterval line, and it seems to have something
to do with the fact I want to pass the function clockUpdate an argument
(I don't want to specify a single text element to be associated with the
display of the clock. Ideally, I'd like to be able to call the function
"fieldToClock" with the id of any text field in the document and turn it
into a clock).
The two commented out lines are other approaches I've applied. The first
approach yields the error:
Error: useless setInterval call (missing quotes around argument?)
Source File: http://weston.canncentral.org/misc/tkeep/tkeep.jss
Line: 6
The second/third approach yeild:
Error: clock_STF is not defined
Source File: http://weston.canncentral.org/misc/tkeep/tkeep.jss
Line: 7
Except this error is repeated every 1000 seconds.
Any ideas?
Thanks,
Weston