I try to change a button text after click for a few seconds. On the page are buttons dynamically build by a PHP database while loop. Every button gets an id dynamically like button0, button1, button2 etc.....
echo "<a href='rdp://" . $record["ip_adress"] . "'><button id='button".$counter."' type='button' class='button' onclick=\"btn('button".$counter."')\" style='vertical-align:middle'"?>
<?php if($freeusers == 0){echo "disabled>No Login";}else{echo ">Login";}?> <?php echo "</button></a>";
And here the Javascript Code:
<script>
function btn(i){
document.getElementById(i).addEventListener('click', function (clicked) {
return function () {
if (!clicked) {
var last = this.innerHTML;
this.innerHTML = 'please wait...';
clicked = true;
setTimeout(function () {
this.innerHTML = last;
clicked = false;
}.bind(this), 5000);
}
};
}(false), this);
}
</script>
The Button name passes through the function after click. But the programm never reached after if(!clicked){ ... It seems, that it not recognizing a "click" or something. But I dont know what to do.
Greetings