1

I want to recover selectedValue variable javascript in $aaa variable php ?

$aaa = "<script>selectedVal</script>";
$(document).ready(function() {
  $('#example').DataTable({
    "lengthMenu": [
      [10, 25, 50, -1],
      [10, 25, 50, "All"]
    ]
  });
  $(document).on("change", ".dataTables_length select", function() {
    var selectedVal = $(this).val();
  });
});
guradio
  • 15,524
  • 4
  • 36
  • 57
Moslah
  • 39
  • 6

1 Answers1

0

If I understand this question correctly, you are asking to grab a javascript variable from the PHP code. Javascript is executed on the client side, PHP on the server side. This means that the PHP portion is finished executing before it's even sent to the user's web browser. This make the PHP code unable to "see" javascript variable.

If you want, in the other case, to set a javascript variable based on a PHP one, a simple solution would be:

<script type="text/javascript">
        var selectedVar = "<?php echo $aaa; ?>";
        ...

That will be seen from the user as:

<script type="text/javascript">
        var selectedVar = [$aaa variable content];
        ...

I hope this was helpful!

Francesco
  • 429
  • 4
  • 12