i am completely new to JS… I’ve learnt the basics in about 15 minute
so i could create a countdown.
I guess i could finish it but the problem is i’ll have way too many IF statements
one in each other… i was hoping there is an easier way to do it…
here’s what i have done so far
(it probably looks silly but it’s the first thing i am creating with JS)
i’ll change the text boxes later into divs….
[CODE]
<input type=”text” id=”sec”>
<input type=”text” id=”min”>
<input type=”text” id=”hour”>
<input type=”text” id=”days”>
<script type=”text/javascript”>
countdown()
var rsec= <?php echo $time; ?>
var sec = rsec%60
var rmin = rsec/60
rmin = parseInt(rmin)
var min = rmin%60
var rhour = rmin/60
rhour = parseInt(rhour)
var hour = rhour%24
var rday = rhour/24
rday = parseInt(rday)
var day = rday
day = parseInt(day)
function countdown()
{
document.getElementById(‘min’).value=min
document.getElementById(‘sec’).value=sec
document.getElementById(‘hour’).value=hour
document.getElementById(‘days’).value=day
sec=sec-1
if (sec==-1)
{
sec = 59
min = min-1
if (min==-1)
{ // …… you can see how long it’s going to be if i continue
//this way, that’s why i am asking if there’s something simpler
// i could use.
}
}
t=setTimeout(“countdown()”,1000)
}
</script>