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
tetsuO2
Forum Newbie
Posts: 16
Joined: Thu Aug 10, 2006 6:33 am

JavaScript in PHP

Post by tetsuO2 »

Code: Select all

echo "<a href='display.php?pid=".$row["productID"]."' target='_blank' onClick='if (window.open){window.open('display.php', 'new', 'scrollbars=no,width=100,height=100,resizable=yes');return false; }'>";
echo "<img src=".$row["productIMG"]." width='70' height='70'>";
echo "</a>";
When i click the link img($row["productIMG"]), it works. New window open.
But new window's SIZE is much bigger than width='100' height='100'.
The size should be width=100,height=100 in this case.

*when i use this code without PHP, it works perfectly.

If u know what is wrong, plese teach me.
and also, when i use javascript in PHP code, in general what should i be carefull?
Thanks in Advance.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Maybe

Code: Select all

width='100px' height='100px'
tetsuO2
Forum Newbie
Posts: 16
Joined: Thu Aug 10, 2006 6:33 am

Post by tetsuO2 »

Code: Select all

width='100px' height='100px'
I tried this , but still does not work..
Thanks for the reply anyway.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You've got logical problems with the quotes you've chosen to use.
tetsuO2
Forum Newbie
Posts: 16
Joined: Thu Aug 10, 2006 6:33 am

Post by tetsuO2 »

Could u teach me the logical problems?

For me it looks fine....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the code that you use in where this works? Compare that to the output generated by your code. There are likely subtle differences.
User avatar
Mastermind
Forum Commoner
Posts: 36
Joined: Thu Mar 10, 2005 2:38 am
Location: CDO,Philippines
Contact:

Post by Mastermind »

I thinks it is a combination between php and javascript that call ajax.
tetsuO2
Forum Newbie
Posts: 16
Joined: Thu Aug 10, 2006 6:33 am

Post by tetsuO2 »

Code: Select all

<a href="display.php?pid=<?php echo $row[0]; ?>" target="_blank"  onClick="if (window.open){window.open('display.php?pid=<?php echo $row[0]; ?>', 'new', 'scrollbars=yes,width=550,height=340,resizable=yes');return false; }">
As feyd said, I need to be more carefull of this.

anyway i figured it out.
I need to out quotes in front of "if" and in back of "}".
then it works perfectlly.


I was just half-baked of this.

Thank you.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

When dealing with javascript output I often find it useful to use heredoc string declarations to simplify quoting:

Example 11-4. Heredoc string quoting example (Taken from Strings)

Code: Select all

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
/* More complex example, with variables. */
class foo
{
   var $foo;
   var $bar;

   function foo()
   {
       $this->foo = 'Foo';
       $this->bar = array('Bar1', 'Bar2', 'Bar3');
   }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;?>
Post Reply