views:

35

answers:

1

I have a form with a submit button. I want to disable the submit button for 10 seconds, and show a countdown, at the end of which the button becomes clickable.

How would I do that? Im using jquery on the site, but Im not a JS programmer.

+4  A: 

Let's keep it simple. If you'd like an explanation of what is going on, let me know:

    <html>
    <head>
    <script type="text/javascript">
        setTimeout (function(){
        document.getElementById('submitButton').disabled = null;
        },10000);

        var countdownNum = 10;
        incTimer();

        function incTimer(){
        setTimeout (function(){
            if(countdownNum != 0){
            countdownNum--;
            document.getElementById('timeLeft').innerHTML = 'Time left: ' + countdownNum + ' seconds';
            incTimer();
            } else {
            document.getElementById('timeLeft').innerHTML = 'Ready!';
            }
        },1000);
        }
    </script>
    </head>

    <body>
    <form>
        <input type="submit" disabled="disabled" id="submitButton" />
        <p id="timeLeft">Time Left: 10 seconds</p>
    </form>
    </body>
</html>
Cody Snider
Thats perfect. Thank you!
Yegor