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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

SQL Server - MyCTE query based on 24 hour period (next day) -