如何将包含JS的PHP var放入表单值?

I have a javascript to generate ETH address and private keys. I want to output the value of the private key and the address to a hidden field in a registration form.

However..

As plain PHP, this outputs the desired results:

$wallet_address = "<script type='text/javascript'>document.writeln(wallet.address);</script>";

echo $wallet_address;

But, when I try and put the $wallet_address into a form field:

<input type="hidden" name="user_wallet" id="user_wallet" class="input" value="<?php echo $wallet_address; ?>" />

I dont get the address, I get the javascript source line: <script type='text/javascript'>document.writeln(wallet.address);</script>

How do I get the value of $wallet_address to be the actual address in the form field?

You echo the script, not the render of the script;

Do sth like :

 $wallet_address = '<script type="text/javascript">function writeWallet(){ document.getElementById(user_wallet).value = "yourAdress";} window.onLoad(writeWallet);</script>';