Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  6] [ 6]  / answers: 1 / hits: 16321  / 11 Years ago, wed, october 16, 2013, 12:00:00

I want to be able to edit something inside of a heredoc syntax. Something like this:



index.php:



$var = <<<HTML
<form action=index.php method=get id=forma>
<input type=radio name=choice value=value>Message<br>

</form>
HTML;
...
$form = $var;


js:



<script>
document.getElementById('forma').open();
document.getElementById('forma').write('<input type=submit>');
document.getElementById('forma').close();
</script>


EDIT: My goal is to have a button to go to a new page, but the button won't be present until you click OK on a JS confirm() popup.


More From » php

 Answers
23

What you are trying to do (change the HEREDOC) is impossible.



The PHP gets interpreted on the server and the result is a HTML file with some embedded JS.
Only after this HTML file gets to the client and is interpreted, the JS is executed. At this point the original PHP file containing the HEREDOC is long gone.



What you can do however is manipulate the DOM on the client side, but you should look to element.innerHTML as an alternative to document.write.


[#74947] Tuesday, October 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yisroels

Total Points: 256
Total Questions: 94
Total Answers: 102

Location: Chad
Member since Mon, Dec 5, 2022
2 Years ago
;