I read several examples, tried them all out - and nothing works! Driving me crazy - completely insane! Maybe you guys can help
My problem is simple:
file B.html includes this line:
file B.js is a regular JS file, yet I need to insert a PHP function in it (yeah - I know it will operate server-side before the page reaches the browser). I did something like:
(some js code)
[B]var user_id = <?php $a=100; $b=200; $c=$a+$b; echo($c);?>;
[/B]alert("Your user ID is:" + user_id);
(some more js code)
(What I expect is the browser to see the line as: var user_id = 300; )
Doesn't work. Renaming B.js to B.php did nothing.
What am I doing wrong?
If your external JS has PHP, then the file needs to be a PHP file, then call it in the script src:
var user_id = <?php $a=100; $b=200; $c=$a+$b; echo($c);?>;
alert("Your user ID is:" + user_id);
Call it in your HTML file: