Reputation: 1
I am storing the result of some calculations in a HTML div
element using the innerHTML
attribute:
var result = document.getElementById('duration').innerHTML+
obj1+" "+obj+" "+
km.toFixed(1)+" Km "+Date
document.getElementById('duration').innerHTML = result
Now I want to store the div
's content/data in a PHP variable.
Upvotes: 0
Views: 1292
Reputation: 414
After set dic content, use jQuery to send data to PHP:
var url = 'myPHPFile.php';
$.post(url, {data: document.getElementById('duration').innerHTML});
In your PHP , get your variables from $_POST['data']:
<?php
$data = $_POST['data'];
?>
Upvotes: 1
Reputation: 1583
JavaScript is on client side, so you can try to send JS variable (div content) back via URL and then obtain it via PHP. JS like this:
window.location.href=”index.php?divContent=" + document.getElementById('duration').innerHTML;
And then in PHP obtain it from GET, like this:
$somevar = $_GET["divContent"];
Upvotes: 0