Can you please help me with load variable from PHP to Javascript?
Example:
<head>
<script scr="../js/alert.js">
file alert.js
var myAlert = "<?php echo $_SESSION['information']; ?>";
alert(myAlert);
But final solution is, that the alert message is
<?php echo $_SESSION['information']; ?>
If I use var myAlert = <?php echo $_SESSION['information']; ?>;
without the quotation marks it writes me error “Expected jsx_identifier but found error…”
Can someone help me with that please?
I am trying load PHP variable to Javascript to use it in js code.
New contributor
Tomáš Rejka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1