javascript in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

javascript in php

Post 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]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: javascript in php

Post 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! ;)
(#10850)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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>";
?>
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Try using heredocs
Post Reply