0

Can I please have some help in using a PHP variable in some Javascript code. i want to use php code in javascript function how to use php scripts in javascript function for example i want to use php code in this javascript function

function rank()
{
<?php echo'hello';?>
}
user204570
  • 31
  • 2
  • It probably won't work because PHP runs on server side. If you still want interaction you need to use Ajax. – Rolen Koh Feb 04 '14 at 10:16

3 Answers3

-1

Try using like this

function rank()
{
 var someVariable = "<?php echo 'hello';?>";
}
Suresh Kamrushi
  • 14,655
  • 12
  • 74
  • 87
-1

try this (better & shorter)

function rank()
{
    var variable="<?='hello';?>"
}
saman khademi
  • 802
  • 6
  • 13
-2

You can use like this:

function rank()
{
  var rankVar;
     rankVar = "<?php echo'hello'?>";
}
user2936213
  • 1,041
  • 1
  • 8
  • 19