Page 1 of 1
JavaScript in PHP
Posted: Sun Sep 03, 2006 6:54 pm
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.
Posted: Sun Sep 03, 2006 6:57 pm
by tristanlee85
Posted: Sun Sep 03, 2006 7:05 pm
by tetsuO2
I tried this , but still does not work..
Thanks for the reply anyway.
Posted: Sun Sep 03, 2006 9:15 pm
by feyd
You've got logical problems with the quotes you've chosen to use.
Posted: Sun Sep 03, 2006 11:15 pm
by tetsuO2
Could u teach me the logical problems?
For me it looks fine....
Posted: Sun Sep 03, 2006 11:17 pm
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.
Posted: Mon Sep 04, 2006 12:13 am
by Mastermind
I thinks it is a combination between php and javascript that call ajax.
Posted: Mon Sep 04, 2006 2:21 am
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.
Posted: Mon Sep 04, 2006 3:56 am
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;?>