javascript - call php var inside JS -


could tell me why not working ?

<html> <body>  <?php $var1 = "hello"; echo $var1; ?>  <button type="button" onclick="document.getelementbyid('demo').innerhtml = <?php echo(json_encode($var1)); ?>;"> hi</button>  <p id="demo"></p>  </body> </html> 

what should able read php variable js ? thanks

it string. 's needed added around string.

onclick="document.getelementbyid('demo').innerhtml = '<?php echo(json_encode($var1)); ?>';" 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -