A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearjavascript function not working - page 1
User InfoPosts
javascript function not working#1
i have the following javascript code:


in which the function makewindows does not seem to be working.

it does actuall create a window, however the html either contains what is quotes, or if I change it to


creats 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:


and test3.php


posted date: 2008-12-08 04:21:00

Re: javascript function not working#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-08 04:21:01

Re: javascript function not working#3
$row2["ARTICLE_DESC"] is PHP variable.

posted date: 2008-12-08 04:23:00

Re: javascript function not working#4
to print php variable you need php tags:child1.document.write(<?php echo json_encode($row2["ARTICLE_DESC"]); ?>);

posted date: 2008-12-08 04:26:00

Re: javascript function not working#5
Thanks for the password. Hope it's not real.

posted date: 2008-12-08 04:52:00

Re: javascript function not working#6
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();}

posted date: 2008-12-08 04:56:00

Re: javascript function not working#7
$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 ?> tagsSo, 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.

posted date: 2008-12-08 05:01:00

Re: javascript function not working#8
Would it be more logical to allow the function to take a parameter, or to use the above method. What would be the respective advantages/disadvantages?

posted date: 2008-12-08 05:10:00

Re: javascript function not working#9
That gives an error without telling what the error is..missing quotes?

posted date: 2008-12-08 05:48:00

Re: javascript function not working#10
No problem, have fun on

posted date: 2008-12-08 06:57:00

Re: javascript function not working#11
yes tomhaigh is right...corrected the error now.

posted date: 2008-12-08 13:25:00

Re: javascript function not working#12
u need quotes here: document.write('<?php ?>');

posted date: 2008-12-08 13:27:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.