Hi all, does anyone know a way to disable a button after x minutes after pageload? Preferably also with a visual counter like (x minutes to go) . It's for a timebased test im creating. Thanks in advance
If you're intending to disable it for a variety of page viewers (not just yourself, for testing purposes) then you may be searching for space, the final frontier, considering that "x minutes" will differ depending upon connection speed, computer power, browser screen refresh rate, other activities on the particular computer at the given moment, and other unpredictables...
Answers & Comments
Verified answer
1. set the time to countdown, initiate current time,
2. flag finish loading of page by a script line just before </body>
3. build function for disable button
4. build function for recursive time check and update label
5. make form for button and label
Put the following between the <head> tags
<script LANGUAGE = "Javascript" type="text/javascript">
var sec2disable=7;//seconds to disable button
var now1 = new Date();
var show=1;
var starttime = parseInt(now1.getTime()/1000);
function ldfin(){
document.forms[0].lab1.value=sec2disable;
c2d();
}
function c2d(){
var now2 = new Date();
if (parseInt(now2.getTime()/1000) == starttime+sec2disable) {document.forms[0].but1.disabled=1;}
if ((show == 1) && (document.forms[0].lab1.value>0)){ document.forms[0].lab1.value= sec2disable-(parseInt(now2.getTime()/1000)-starttime);
setTimeout("c2d()",1000);}
}
</script>
put the following between the <body> tags
<form><input type="button" name="but1" value="Click me to stop count" onclick="alert('Button working, count stopped!'); show=0;"><br><br>
Time left before button become disabled<br>
<input type="label" name="lab1" value=" "></form>
<SCRIPT LANGUAGE = "Javascript" type="text/javascript">ldfin();</SCRIPT>
To see a demo which illustrate the above with IE, mozilla & Opera use this link http://www.freewebs.com/swhtam/YA/disableButton.ht...
If you're intending to disable it for a variety of page viewers (not just yourself, for testing purposes) then you may be searching for space, the final frontier, considering that "x minutes" will differ depending upon connection speed, computer power, browser screen refresh rate, other activities on the particular computer at the given moment, and other unpredictables...