Forum Moderators: open
<html><head>
<script type="text/javascript">
<!--
function disable(el,time){
var elid = el.id;
el.disabled = true;
setTimeout( "undisable("+elid+")" , time*1000);
}
function undisable(elid){
alert('Undisabling: '+elid);
var el = document.getElementById(elid);
el.disabled = false;
}
//-->
</script>
</head><body>
<input type="button" onclick="disable(this,2);" value="Click and I will briefly become unavailable" />
</body></html>
The code successfully disables the input but does not enable the input when the settimeout fires. Instead "elid" reports as "undefined"
I'm in the weird position of having buttons I need to prevent the possibility of a double-click, but allow later clicks. :/
I already have a CSS display toggle (none<=>block) but the button disappearing is just silly looking.
<html><head>
<script type="text/javascript">
<!--
function disable(el,time){
var elid = el.id;
el.disabled = true;
setTimeout( "undisable('"+elid+"')" , time*1000);
}
function undisable(elid){
alert('Undisabling: '+elid);
var el = document.getElementById(elid);
el.disabled = false;
}
//-->
</script>
</head><body>
<input type="button" onclick="disable(this,2);" value="Click and I will briefly become unavailable" id="foo" />
</body></html>