as i said in the comments, i tried this too but it doesn't work (as i said before, it is not possible to add the following script to the index page, this means that any script solution must be done on this check page)
index.php :
$nonce = 'n123'; //base64_encode(random_bytes(16));
check.php :
echo '<button type="button" id="btn" value="' . $_POST['username'] . ' : ' . $_POST['password'] . '">' . $_POST['username'] . '</button><script nonce="n123">document.getElementById("btn").addEventListener("click", function () { this.innerText = this.value; });</script>';