<html>
<head>
<script type="text/javascript">
var text;
function setText(type, elem,timeLeft){
timeLeft = (timeLeft) ? ' ('+timeLeft+')' : '';
if(type == 'button'){
elem.innerHTML = text+timeLeft;
} else {
elem.value = text+timeLeft;
}
}
function disableButton(timeLeft,id,type){
elem = document.getElementById(id);
elem.disabled = 'disabled';
//Button-Text zwischenspeichern
if(!text || !type){
if(elem.innerHTML){
type = 'button';
text = elem.innerHTML;
} else {
type = 'submit';
text = elem.value;
}
}
text = (text) ? text : ((elem.innerHTML) ? elem.innerHTML : elem.value);
//verbleibende Zeit anzeigen
setText(type,elem,timeLeft);
if(timeLeft > 0){
// angegebene Wartezeit ist noch nicht vorbei,
timeLeft-=1;
// daher selbstaufruf
setTimeout("disableButton('"+timeLeft+"','"+id+"','"+type+"')",1000);
} else { // angegebene Wartezeit ist vorbei
setText(type,elem);
elem.disabled = '';
}
}
</script>
</head>
<body onload="disableButton(5,'button1');">
<input type="submit" value="Button-Text" id="button1"/>
<!--<button id="button1">Button-Text</button>-->
</body>
</html>