Answer the question
In order to leave comments, you need to log in
Why is the callback function not working?
Good afternoon!
Please help: I need to run function 2 right after function 1 finishes. I'm trying to do it using a callback, but so far without success. I tried it completely: function run(){if(!func1()){func2();}}
, but when launched in the browser, the page started to really shake and twitch)
Here is the whole code, these are 2 timers that should be launched sequentially, in accordance with the given values.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Pomodoro</title>
<meta name="" content="" charset="utf-8">
<link href="pomodoro.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>Pomodoro</p>
<div id="Mytimer"><p><a id="timer" href="javascript:tiktak(tiktak1)">count!</a></p></div>
<div id="first">
<p><input type="text" id="volume" value="5" /></p>
<input type="button" value="+" onClick="inc()">
<input type="button" value="-" onClick="dec()">
</div>
<div id = "sec">
<p><input type="text" id="volume1" value="2" /></p>
<input type="button" value="+" onClick="inc1()">
<input type="button" value="-" onClick="dec1()">
</div>
<script>
var ch = document.getElementById("volume").value*60;
//console.log(ch);
function inc(){ch+=60;document.getElementById("volume").value = Math.floor(ch/60);}
function dec(){ch-=60;document.getElementById("volume").value = Math.floor(ch/60);}
function inc1(){ch+=60;document.getElementById("volume1").value = Math.floor(ch/60);}
function dec1(){ch-=60;document.getElementById("volume1").value = Math.floor(ch/60);}
function tiktak(tiktak1){
if(ch >= 60){
minute = Math.floor(ch/60);}
var second = ch - minute*60;
if(ch<60){minute = 0;}
if(minute<=9){minute = "0" + minute;}
if(ch<=9){second = "0" + second;}
if(document.getElementById){timer.innerHTML = minute + ":" + second;}
//if(ch==00){return false;}
if(ch==00){tiktak1.call();}
ch--;
setTimeout("tiktak()", 1000);
}
var ch1 = document.getElementById("volume1").value*60;
var tiktak1 = function(){
if(ch1 >= 60){
minute = Math.floor(ch1/60);}
var second = ch1 - minute*60;
if(ch1<60){minute = 0;}
if(minute<=9){minute = "0" + minute;}
if(ch1<=9){second = "0" + second;}
if(document.getElementById){timer.innerHTML = minute + ":" + second;}
if(ch1==00){return false;}
ch1--;
setTimeout("tiktak1()", 1000);
}
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
setTimeout("tiktak()", 1000);
do you catch the difference in calling a function with and without arguments?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question