1

I'm trying to get PHP variables into javascript however I'm having some issues. In testing, I'm trying to verify that it works. I've used variations of the following code and either got an alert with the actual PHP call or got an error.

Tried this: (an alert is generated but of the actual PHP call as a string basically, not the actual naming variable or moo)

function jvtest()
{
    $naming = "moo";

    echo '<script type="text/javascript"> 
    var x = "<?php echo $naming ?>";
    alert(x);
    </script>';
}

And this. Generates a PHP error.

function jvtest()
{
    $naming = "moo";

    echo '<script type="text/javascript"> 
    var x = "'<?php echo $naming ?>'"; <-- error on this line
    alert(x);
    </script>';
}

Any idea of how to resolve this? Thanks

jack bauer
  • 23
  • 5

0 Answers0