Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get JavaScript variables in PHP?

Tags:

javascript

php

I builded my own online javascript editor, but when I submit form, javascript not work. Here are my codes:

editor.php

<form action="show.php" method="post" target="window">
HTML code:<br />
<textarea name="html"></textarea><br />
JavaScript code:
<textarea name="javascript"></textarea><br />
<input type="submit" value="Test javascript" />
</form>
<iframe src="show.php" width="880" height="600" name="window"></iframe>

show.php

<html>
<head>
</head>
<body>
<?php
  if(isset($_POST['html'])) echo $_POST['html'];
  echo "<br><br>";
  if(isset($_POST['javascript'])){
    echo "<script>";
    echo $_POST['js'];
    echo "</script>";
  }
?>
</body>
</html>

HTML works well, but when I say something in javascript textarea, javascript will not work in iframe. Please, help me.

like image 945
user1924244 Avatar asked Jun 26 '26 21:06

user1924244


1 Answers

From your code I see no input field with name js, hence I assume the following:

echo $_POST['js'];

should be:

echo $_POST['javascript'];

Otherwise, your code should work fine.

like image 137
VisioN Avatar answered Jun 29 '26 11:06

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!