I want to change the content in javascript of a textbox while using PHP.
If I change it with plain Text as:
echo "<script> var test = 0; simplemde.value('test');
test+= 5; alert(test);</script>";
it works. But with a php-Variable it isn't working any longer:
echo "<script> var test = 0; simplemde.value('$markdown');
test+= 5; alert(test);</script>";
Not sure what I'm doing wrong. If I open the site and watching the source-text it stands in the correct form there but It isn't in the box.
Here is my full code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./css/markdown.css">
<script src="./js/markdown.js"></script>
</head>
<body>
<textarea id="myID">
</textarea>
<script>
var simplemde = new SimpleMDE({
element: document.getElementById("myID"),
spellChecker: false,
});
</script>
<?php
require_once './Michelf/Markdown.inc.php';
use \Michelf\Markdown;
require_once 'loader.php';
$json_a = load();
if(count($json_a) > 0)
{
$text = $json_a[0]['blog'];
echo "found";
}
else
echo "not found";
$markdown = Markdown::defaultTransform($text);
echo $markdown;
echo "<script> var test = 0; simplemde.value('test'); test+= 5;
alert(test);</script>";
echo "<script> var test = 0; simplemde.value('$markdown');
test+= 5; alert(test);</script>";
?>
</body>
</html>
scriptrendered as you wanted it to be ?alerttwo times or one?