Reputation: 4193
I have the following JavaScript code: Link
In which the function makewindows does not seem to be working.
It does actual create a window, however the html either contains what is quotes, or if I change it to
child1.document.write(json_encode($row2["ARTICLE_DESC"]));
to create a blank html page.
I moved this function to my main JavaScript file to include because I was getting errors before, but now no HTML is presented in the popupwindow. Is this because I am not retrieving article_Desc in thest3.php?
The other 2 files used are here: link and test3.php
Upvotes: 1
Views: 676
Reputation: 107950
$row2["ARTICLE_DESC"] is PHP variable.
It is indeed a php variable, but it is not being rendered as php because it is not enclosed in <?php ?>
tags
So, the correct way to do it is:
child1.document.write(<?php echo json_encode($row2["ARTICLE_DESC"]); ?>);
That way, the php, being a server side language, will render the value in $row2 before the page is rendered, so when the page finally gets rendered, that value will be in the javascript write
function...as it's supposed to be.
Upvotes: 4
Reputation: 532465
I suspect that it is including the javascript after it has been parsed by the PHP interpreter. Try adding a parameter to makewindows and pass the value you intend to use in via the parameter when you construct the 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();
}
Upvotes: -1
Reputation: 3321
to print php variable you need php tags:
child1.document.write(<?php echo json_encode($row2["ARTICLE_DESC"]); ?>);
Upvotes: 2