Skip to main content
Clarification that the reverse approach is just a btw
Source Link
halfer
  • 20.2k
  • 19
  • 110
  • 207

This is because PHP is run on the server, and your JS executes on the client. YouJust as an aside, you can do things the other way, so in JS:

<script type="text/javascript">
    var myval = '<?php echo $myphpval ?>';
</script>

This is possible because the PHP executes on the server before the JS executes on the client. If however you want to send a JS value to a PHP script, then you will need to do it after the DOM has loaded, usually via an AJAX call.

This is because PHP is run on the server, and your JS executes on the client. You can do things the other way, so in JS:

<script type="text/javascript">
    var myval = '<?php echo $myphpval ?>';
</script>

If however you want to send a JS value to a PHP script, then you will need to do it after the DOM has loaded, usually via an AJAX call.

This is because PHP is run on the server, and your JS executes on the client. Just as an aside, you can do things the other way, so in JS:

<script type="text/javascript">
    var myval = '<?php echo $myphpval ?>';
</script>

This is possible because the PHP executes on the server before the JS executes on the client. If however you want to send a JS value to a PHP script, then you will need to do it after the DOM has loaded, usually via an AJAX call.

Source Link
halfer
  • 20.2k
  • 19
  • 110
  • 207

This is because PHP is run on the server, and your JS executes on the client. You can do things the other way, so in JS:

<script type="text/javascript">
    var myval = '<?php echo $myphpval ?>';
</script>

If however you want to send a JS value to a PHP script, then you will need to do it after the DOM has loaded, usually via an AJAX call.