by Nobbie » 28. May 2021 19:26
First of all, you have to understand how processing and data flow is working.
Most important is the understanding, that PHP is running far earlier than JavaScript, these are running in a totally different scope and there is no connection between these. That is what you MUST understand. Normally, a webserver is a remote PC somewhere in the world, but not your desktop PC running your browser. Think of Google, think of this forum - these things are running on remote computers, not on your computer.
PHP is executed by the webserver, actually Apache sends it to the PHP interpreter (which must be installed on the webserver). After PHP has finished, Apache sends the resulting output to your browser (via TCPIP). So, when your browser receives the HTML file which contains the JavaScript commands, PHP has already finished and there is no PHP anymore. Not on your PC. All PHP coding like "echo $variable" is replaced by the output of the statement already on the webserver.
Last not least, your browser receives the resulting HTML and JavaScript, which does not contain any PHP source. And then your browser executes the JavaScript.
And now think about, how data flow is running in your application and how you can have values from PHP variables in your JavaScript. I dont say, that doesnt work. But surely it works differently as you may believe. I actually dont know what you are trying to do, you did not give us a proper description, but as already said, you MUST have an idea, how PHP is working and how JavaScript is working. And why it may be difficult to have PHP variables in your JavaScript Code. I hope you get it properly, if not, do not hesitate to ask. It is most important that you get full knowledge about the realisation of PHP and JavaScript. These do not run at the same time and not in the same scope.