0

The result is saved and displayed on the first page, but on page 2 appears:

"+javavar+"

There should be the text I prepared in the input

page1.php:

<html>
<body>

<input onkeyup="jstophp()" onpaste="jstophp()" id="text">te</input>

<script>
function jstophp(){
javavar=document.getElementById("text").value;

document.getElementById("rslt").innerHTML="<?php 
session_start();
$var='"+javavar+"';
echo $var;
$_SESSION['test'] = $var;
?>";}
</script>

<div id="rslt">
</div>
</body>

page2.php:

<?php
session_start();
$text = $_SESSION['test'];
echo $text;
?>
  • Your formatting is making my eyes bleed, and nothing in that code passes anything to anything. SESSIONs are server side, you need some sort of get\post etc request to modify them after page load. – Mason Stedman Apr 28 '18 at 11:00
  • You cant pass a JS variable to PHP. You can however use AJAX calls and then catch them in PHP. – Sylent Apr 28 '18 at 11:00

0 Answers0