Forum Moderators: coopster

Message Too Old, No Replies

Help with printing Javascript with PHP

Cant quite get this right, please help

         

garyw74

9:43 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Hi

I am generating a HTML page with PHP and I need a pop window link.

So far I have got this but i just get a blank space where "Click here to view" should be.

$lc_text .= 'here to<br> <script language="javascript"><!-- document.write(\'<a href="javascript:popupWindow(\'http://www.domain.co.uk/product_ximage.php?products_id=' . $listing_values['products_id'] . '\')">Click here to view</a>\'); //--></SCRIPT><br>to here<br><BR>';

Can anyone help please
Thanks in advance

jatar_k

9:46 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld garyw74,

try viewing the page source, it should give you a hint as to what is wrong with the statement

garyw74

9:50 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Thanks, but looks pretty much how it should i think. Image number variable and everything. In fact if I compare it to a working copy in dreamweaver its exact.
Here it is

<BR><BR>here to<BR>
<SCRIPT language=javascript><!-- document.write('<a href="javascript:popupWindow('http://www.domain.co.uk/product_ximage.php?products_id=3492')">Click here to view</a>'); //--></SCRIPT>
<BR>to here<BR>

jatar_k

10:07 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



has to do with quote escaping, took me a bunch of tries to make it work

if you use mozilla or firefox they have a js debugging tool you can use by typing javascipt: into the location bar and hitting enter

I made this work

<?
$listing_values['products_id'] = 44;
$lc_text .= 'here to<br>';
$lc_text .= '<script type="text/javascript">';
$lc_text .= 'document.write("<a href=\\"javascript:popupWindow(\'http://www.domain.co.uk/product_ximage.php?products_id=' . $listing_values['products_id'] . '\')\\">Click here to view</a>");</script>';
$lc_text .= '<br>to here<br><BR>';

echo $lc_text;

?>

[edited by: jatar_k at 10:14 pm (utc) on Mar. 6, 2006]

garyw74

10:13 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Fantastic. Your a star. Works a treat
Thanks

jatar_k

10:13 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it is the double escape because the js needs one and the php needs one

crazy