I have a table where it displays the ID and on click I get the ID. I then used Json and sent it to page editReport.php where i want to get to the variable to view the report I wish to edit. Can I get it to a php variable on the editReport page. I have used JSON to populate a javascript variable with PHP but cant find a way to get javascript to PHP.
//Reports.PHP
function myFunction() {
$(".reportId").click(function () {
var selectedReportId = $(this).text();
//alert to test if gets ID from click
alert(selectedReportId);
selectedReportId = JSON.stringify(selectedReportId);
localStorage.setItem('selectedReportId', selectedReportId);
window.location = "editReport.php";
});
}
this here is the page the var is sent to. Any possible way to get that variable into a PHP var
//editReports
<script type="text/javascript">
function myFunction() {
alert("hi");
var selectedReportId = localStorage.getItem('selectedReportId');
if (selectedReportId) selectedReportId = JSON.parse(selectedReportId);
alert(selectedReportId);
$.post('editReport.php', {variable: selectedReportId});
}
<?php
//make this variable populated from the javascript
$varID = $_POST['variable'];
echo "$varID";
?>