Why does the click not respond?

<?php
$str1="Hello";
$str2="start PHP";
echo "<script>";
echo "alert("".$str1."");";
echo "</script>";

?>

<input type="text" name="tx" size="20" value="<?php echo $str1;?>">
<input type="button" value="click" onclick="tx.value="<?php echo $str2;?>"">



ok

Why does not start PHP? appear when clicking click,

Php
Apr.03,2021

tx is not defined

change onclik to:

onclick="var tx = document.getElementsByTagName('input')[0];tx.value='<?php echo $str2;?>'"

Not even F12?

clipboard.png


Brother, your tx is not defined, and the browser doesn't know who tx is. If you want it to do something, you have to tell it who tx is. Change it, for example:

<input type="button" value="click" onclick="document.getElementsByName('tx')[0].value=''">
Menu