tags:

views:

92

answers:

1

I think the title says it all.

I'm trying to use this code to countdown from 10 seconds, then show a link.

x116=30;
FUNCTION countdown() 
{
IF ((0 <= 100) || (0 > 0))
{
x116--;
IF(x116 == 0)
{
document.getElementById("dl").innerHTML = '<a href="download.php">Download</a>';
}
IF(x116 > 0)
{
document.getElementById("dl").innerHTML = 'Please wait <b>'+x116+'</b> seconds..';
setTimeout('countdown()',1000);
}
}
}
countdown();

I just know some really basic javascript. So could anyone tell me whats wrong with this? Nothing happens basically.

Cheers

+2  A: 

Try this:

var container = document.getElementById('dl');
var seconds = 10;
var timer;
function countdown() {
    seconds--;
    if(seconds > 0) {
        container.innerHTML = 'Please wait <b>'+seconds+'</b> seconds..';
    } else {
        container.innerHTML = '<a href="download.php">Download</a>';
        clearInterval(timer);
    }
}
timer = setInterval(countdown, 1000);
Paolo Bergantino