<script>
var seconds = "PRENDO I SECONDI DAL DB";
function $(id) {
return document.getElementById(id);
}
function addOnload(f) {
var prev = window.onload;
window.onload = function() {
if (prev) prev();
f();
}
}
function writecounter(hh, mm, ss) {
$('ore').value = (hh < 10)? "0"+hh : hh;
$('min').value = (mm < 10)? "0"+mm : mm;
$('sec').value = (ss < 10)? "0"+ss : ss;
}
function startcount() {
hh = Math.floor(seconds / 3600);
mm = Math.floor((seconds - (hh*3600)) / 60);
ss = seconds - (hh*3600) - (mm*60);
writecounter(hh, mm, ss);
seconds--;
if (seconds != -1) {
setTimeout('startcount()', 1000)
}
else {
// fai qualcosa
alert("ho finito!");
}
}
var hh = Math.floor(seconds / 3600);
var mm = Math.floor((seconds - (hh*3600)) / 60);
var ss = seconds - (hh*3600) - (mm*60);
addOnload(startcount);
</script>
<body>
<form>
<input type="text" size="2" id="ore" readonly="readonly" /> :
<input type="text" size="2" id="min" readonly="readonly" /> :
<input type="text" size="2" id="sec" readonly="readonly" />
</form>
<script>
writecounter(hh, mm, ss);
</script>
</body>