Trying to call a function when system clock reach a certain time.
Please assist me. I the code is set to alert when the clock reaches a certain time then alert which works.
The problem I am having how is each tick of time after the time the alert continues to popup.
Each day at the chosen time it should pop up just like an alarm clock.
Code:
// JavaScript Document
$(window).load(function (){
$("#submit").click(function () {
var myVar=setInterval(function(){myTimer()},1000);
});
var c = 0.01;
var clock = "15:48:00";
function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("time").innerHTML=t;
if(document.getElementById("time").innerHTML >= clock)
{
alert("I got one more piece almost completed");
clock="00:00:00";
}
}
function callPow(){
var val= document.getElementById("txt").value;
var power= document.getElementById("txt2").value;
alert(Math.pow(val,power));
}
});
callPow is the function that is going to be called every 24 hours just once.
I need there current time to check against the clock is set here var clock = "15:48:01";
When I click the submit button the check for the current time is recording and the clock starts when it reaches "00:00:01" run the callPow function.
save the value of the callPow function in a xml document.
callPow is the function that is going to be called every 24 hours just once.
I need there current time to check against the clock is set here var clock = "15:48:01";
When I click the submit button the check for the current time is recording and the clock starts when it reaches "00:00:01" run the callPow function.
save the value of the callPow function in a xml document.
day to do the same.
Two problems to address since you have not provided the information in your post.
1. Where are you calling the "callPow()" function to see the action?
2. Your check of >= clock (assuming they are of similar format) will be true from "15:48:01" until "23:59:59".
Is that what you want to do in your design?
function callPow(){
If(document.getElementById("txt2").value == ""); // If cannot be capitalized. Cannot end with a ';' here.
{
var val = c;
}
else
{
var val = document.getElementById("txt2").value;
}
I would dispute your statement in post #1 where you say the program works!
Do you have a live site to look at and test. Not your whole site, just this section with the problem in action.
Also, you should enclose your script between [ code] and [ /code] tags (without the spaces)
to make it easier to analyze your scripts.
The callPow is not my problem. I will fix this later I need to make sure the the clock version work first. Focusing on the callPow is secondary.
If I get the clock to work.I can add just the alert to see if it called everyday then I will fix the callPow
If it is not a part of the problem, then leave it out. It still won't work as is.
Your problems:
1. Your contents of the <div> will not equal your setting as programmed.
2. Your comparison will always find any value > "1" to be after "15"
3. Any value less then 10 will display as only 1 digit. Not good for your '00' comparison logic
4. Your .toLocalTimeString() function adds an 'AM' or 'PM' which will not compare to your 'clock' setting.
5. If you don't solve one problem at a time, you are in for a lot of trial & error debugging!
Try this...
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Untitled </title>
</head>
<body>
<div id="timeDIV"></div>
<script type="text/javascript">
Number.prototype.padDigit = function() { return (this < 10) ? '0'+this : this; }
var clock = "15:48:00";
function myTimer() {
var d=new Date();
var t = d.getHours().padDigit()+':'+d.getMinutes().padDigit()+':'+d.getSeconds().padDigit();
if(t >= clock) { t += ' is AFTER '+clock; }
else { t += ' is BEFORE '+clock; }
document.getElementById("timeDIV").innerHTML = t;
}
window.onload = function() { var t = setInterval("myTimer()",1000); }
</script>
</body>
</html>
With this code will run once a day will test. the callPow is function the allows me to multiply the var c that = 0.01 to the 2 power example.
if day one equal 0.01 day two would equal 0.01 + 0.01 = 0.02 day three would equal 0.02 + 0.02 = 0.04. I am testing a theory use the 2 power in math. how could I do this base on a 24:00 time clock.
With this code will run once a day will test. the callPow is function the allows me to multiply the var c that = 0.01 to the 2 power example.
if day one equal 0.01 day two would equal 0.01 + 0.01 = 0.02 day three would equal 0.02 + 0.02 = 0.04. I am testing a theory use the 2 power in math. how could I do this base on a 24:00 time clock.
No actual I am trying to test a theory I was told that if you save a penny and double it everyday in 30 days you will have over a million dollars saved. I just want so if I did this on a web page and just let it sit for 30 and see the return.
I will next time thanks. I just trying to figure out the code myself and get help along the way. What I was really looking for was a way to let sit on my computer for 30 days and see the it calculate each day. But with this I think I can figure it out. I am trying to teach kids the possibility of saving. The code sit on a pc in the classroom and each day for 30 days the will the value change to the new value.
Bookmarks