Forum Moderators: open
I thought my math was correct because it works well throughout the day but it submitted the form at 11:30 ish last night and submitted the value that is supposed to trigger at 5:00.
I'm no JavaScript expert but here is what I have:
<!--
// This script times each portion of the day
// and sets the appropriate value in the IO form
//
// rand() generates a random number between 0 and the number provided
//
// The form is triggered by autoIO() for the following
// values:
// 0 = In
// 1 = Out
// 2 = Lunch
//
function dayGo()
{
Stamp = new Date();
var Hours;
var Mins;
Hours = Stamp.getHours();
Mins = Stamp.getMinutes();
// Set time using the following method
minConvert = 60000; //60 seconds
hourConvert = 60 * minConvert;
// Set time for lunch 12:00
hrLeft = 12 - Hours - 1;
minLeft = 60 - Mins;
if (hrLeft > 0){
lengthOfTime = (hrLeft * hourConvert) + (minLeft * minConvert) + (rand(5) * minConvert);
setTimeout('autoIO(2)', lengthOfTime);
}
// Set time back from lunch 1:00
hrLeft = 13 - Hours - 1;
minLeft = 60 - Mins;
if (hrLeft > 0){
lengthOfTime = (hrLeft * hourConvert) + (minLeft * minConvert) + (rand(5) * minConvert);
setTimeout('autoIO(0)', lengthOfTime);
}
// Set time to go home 5:00
hrLeft = 17 - Hours - 1;
minLeft = 60 - Mins;
if (hrLeft > 0){
lengthOfTime = (hrLeft * hourConvert) + (minLeft * minConvert) + (rand(5) * minConvert);
setTimeout('autoIO(1)', lengthOfTime);
}
// Set time to start over
hrLeft = 14;
minLeft = 60 - Mins;
if (hrLeft > 0){
lengthOfTime = (hrLeft * hourConvert) + (minLeft * minConvert) + (rand(5) * minConvert);
setTimeout('location.reload()', lengthOfTime);
}
}
//-->
The part that seems to not work is the part that sets the time to start over. I've tried making this dynamic (based on what time the script is loaded) and this version is a fixed time, but I can't seem to get either to work.
Any Ideas?
TIMED LOOP : 55 sec // < 1 min
IF ( time = 12:00 OR 1:00 OR 5:00 )
postForm()
ENDIF
ENDLOOP
..and an onload function too.
Not the most efficient, but possibly more efficient, because there's only one timer running (timers take juice). Running this little script very 55 sec isn't going to bother any chip these days.
<!--
// This script times each portion of the day
// and sets the appropriate value in the IO form
var thecount = 0;
function dayGo2()
{
time = "" + now.getHours() + ":" + now.getMinutes();
//Set time in
if ( time = "8:00" ) {autoIO(0)};
//Set lunch time
if ( time = "12:00" ) {autoIO(2)};
//Set lunch over
if ( time = "13:00" ) {autoIO(0)};
//Set time out
if ( time = "17:00" ) {autoIO(1)};
document.ioTimer.loopCount.value = thecount;
thecount += 1;
timeUpdate = setTimeout('dayGo2()',55000);
};
//-->
I added a field to my form so that I could watch the loop execute but it doesn't seem to be working.
Like I said, I just don't "get" JavaScript. It seems like it should be working fine so obviously I'm missing something.