Sponge Bob Sponge Bob - 1 month ago 7
PHP Question

How to use php variable inside a javascript code in a php code?

How can I implement this:

<?php
echo "<script type='text/javascript'>";
echo "document.getElementById('table_apps').innerHTML = json_encode($td_temp);";
echo "</script>";
?>


There is a problem with $td_temp;

Answer

json_encode() is a PHP function

Do like this

echo "document.getElementById('table_apps').innerHTML ='".json_encode($td_temp)."';";
Comments