I am trying to define javascript variable from php variable in the running php code.
Here is my code:
JavaScript
x
echo "<script>";
echo "var s1 = '<?php echo isset($s1) ? $s1 : '' ?>';";
echo "getAirdrop();";
echo "</script>";
But this code not defining the javascript variable.
Advertisement
Answer
You don’t need php tags again.
Try it like this:
JavaScript
echo "<script>";
echo "var s1 = '";
echo isset($s1) ? $s1 : '';
echo "';";
echo "getAirdrop();";
echo "</script>";