0

I want to transfer a variable from php to javascript but keep getting extra quatation marks in the beginning and end echoing it. What have i done wrong and is there a better way to do this?

$textForm = '<form method="post" action="upload.php" name="truth">
<br />
Tittle:<br /><input type="text" name="title" size="40" /> <br /><br />
Author:<br /><input type="text" name="author" size="40" /> <br /><br /><br />
Text:<br /><textarea name="story" cols="90" rows="24" wrap="physical">Input text here.</textarea>


<br /><input type="submit" value="upload" />
<form>';

<script type = "text/javascript">
function showTextForm() {

var form1 = '<?php print json_encode($textForm1); ?>'
</script>

1 Answer 1

1

Think you can simply do:

<script type = "text/javascript">
function showTextForm() {

var form1 = <?=json_encode($textForm1); ?>;
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.