Skip to content
Advertisement

define javascript variable from php variable within php code

I am trying to define javascript variable from php variable in the running php code.

Here is my code:

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:

echo "<script>";
echo "var s1 = '";
echo isset($s1) ? $s1 : '';
echo "';";
echo "getAirdrop();";
echo "</script>";
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement