Page 1 of 1

javascript in php

Posted: Tue Jan 17, 2006 8:05 pm
by $var
twigletmac | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


i'm trying to open a browser window in an echo tag... i put the echoed the javascript according to a goolge explaination...

Code: Select all

<?php
echo "<script type='text/JavaScript'>";
echo" <!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->";
echo "</script>";
include_once("includes/Gallery.class.php");

...

$result .= "<span><a href='#' onclick='MM_openBrWindow('photo.php?id=$index\','pop','scrollbars=yes,resizable=yes,width=600,height=1000') title=\"View Photo $index\"><img src=\"$thumb\" width=\"$width\" height=\"$height\" alt=\"Thumbnail $index\" /></a></span>";
?>
the link works if i open it in a new window using html, but not like this... any suggestions?


twigletmac | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Re: javascript in php

Posted: Tue Jan 17, 2006 10:06 pm
by Christopher
I think you need to get your quotes correct in the HTML around the onClick:

Code: Select all

$result .= "<span><a href=\"#\" onclick=\"MM_openBrWindow('photo.php?id=$index\','pop','scrollbars=yes,resizable=yes,width=600,height=1000');\" title=\"View Photo $index\"><img src=\"$thumb\" width=\"$width\" height=\"$height\" alt=\"Thumbnail $index\" /></a></span>";
It is hard enough the quotes right in the PHP, but then you have to get them right in the HTML that is generated! ;)

Posted: Tue Jan 17, 2006 11:58 pm
by timvw
Here is a little tip that can make the process a lot easier:

Code: Select all

< ?php
$str = addslashes("Hello peter's cats");
echo "<script type='text/javascript'>";
echo "alert('$str')";
echo "</script>";
?>

Posted: Wed Jan 18, 2006 2:31 am
by raghavan20
Try using heredocs