Javascript function not working
I have the following javascript code:
http://www.nomorepasting.com/getpaste.php?pasteid=22561
in which the makewindows function does not work.
it activates window creation, however the html either contains quotes or changes it to
child1.document.write(json_encode($row2["ARTICLE_DESC"]));
creates a blank html page.
I moved this function to my main javascript file to include because I used to get errors, but now the html is not showing in the popupwindow. Is it because I am not fetching article_Desc in thest3.php?
Other 2 files used:
http://www.nomorepasting.com/getpaste.php?pasteid=22562
and test3.php
source to share
$ row2 ["ARTICLE_DESC"] is a PHP variable.
This is indeed a php variable, but it doesn't appear as php because it is not wrapped in tags<?php ?>
So the correct way to do it is:
child1.document.write(<?php echo json_encode($row2["ARTICLE_DESC"]); ?>);
So php, which is a server side language, will render the value on the $ row2 before the page is rendered, so when the page finally gets rendered, that value will be in the javascript function write
... as it should.
source to share
I suspect it includes javascript after it has been processed by the PHP interpreter. Try adding a parameter to makewindows and passing the value you are going to use through the parameter when you generate HTML.
...
<p><a href='#' onclick='makewindows('"
. json_encode($row2["ARTICLE_DESC"])
. "'); return false;'>...
function makewindows(html){
child1 = window.open ("about:blank");
child1.document.write(html);
child1.document.close();
}
source to share