Skip to content
Advertisement

How to send a normal variable’s value from PHP to JavaScript?

I have the below piece of code in my test.php file. The code mainly has a variable defined in PHP, and I want to send it to a JavaScript function so it could POST it. Here’s the code :

JavaScript

But when I run this code, I get this error on console : Uncaught SyntaxError: Unexpected identifier. What should I do if I want to send just a simple string value to the JS code? What’s wrong currently?

Any help is appreciated! Thanks!

Advertisement

Answer

You can do:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement