how to read javascript variable in another php

0

Hi, I'm doing a project in php and I would like to know how you can use the value of a variable that is inside a script in another php page.

This is the script:

<script language="javascript" src="jquery-3.2.1.min.js"></script>
<script language="javascript">

$(document).ready(function(){
     $('#cbx_materia').on('change',function(){
          var id=$('#cbx_materia').val();
          document.getElementById("materia").value = id;
     });
});

</script>

What I want is to use the variable id selected from a combobox on another page, for example report.php, how can I pass that value?

    
asked by Sáber Villalba 02.12.2017 в 14:18
source

2 answers

0

You can have a hidden type input with no assigned value and when you make the selection in the select, you set the selected value with javascript. As the code shows:

<body>

<input type="hidden" name="materia" id="materia" value="">
</body>
<script language="javascript" src="jquery-3.2.1.min.js"></script>
<script language="javascript">

$(document).ready(function(){
     $('#cbx_materia').on('change',function(){
          var id=$('#cbx_materia').val();
          $("materia).val(id)
     });
});

</script>
    
answered by 02.12.2017 в 14:27
0

You can use the POST of JQuery method to send it to PHP like this

$.post( "reporte.php", {idComboBox: id});

and in PHP you get it that way;

$idJavascript = $_POST['idComboBox'];
    
answered by 02.12.2017 в 14:38