My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!
My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!
Share Improve this question edited Apr 24, 2013 at 8:49 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Apr 24, 2013 at 8:42 user2309163user2309163 531 gold badge2 silver badges5 bronze badges 3- 2 have the button with the disabled tag, use a javascript setTimeout() timer for 10 seconds which after that period will change the button property to be not disabled. – Dave Commented Apr 24, 2013 at 8:44
- We can do it by using jquery ... use .hide() – Nipun Tyagi Commented Apr 24, 2013 at 8:44
- We can also do it without using jQuery at all – mplungjan Commented Apr 24, 2013 at 8:46
1 Answer
Reset to default 6You can use javascript like this
<input type="submit" id="submitButton" disabled="disabled" />
using
<script type="text/javascript">
window.onload=function() {
setTimeout(function(){
document.getElementById('submitButton').disabled = null;
},10000);
}
</script>
The following will additionally show a countdown in a container with ID="timeLeft" if you need one
<script type="text/javascript">
var countdownNum = 10;
window.onload=function() {
incTimer();
}
function incTimer(){
setTimeout (function(){
if(countdownNum != 0){
countdownNum--;
document.getElementById('timeLeft').innerHTML = 'Time left: ' + countdownNum + ' seconds';
incTimer();
} else {
document.getElementById('submitButton').disabled = null;
document.getElementById('timeLeft').innerHTML = 'Ready!';
}
},1000);
}
</script>