Page 1 of 1

Mixed PHP and Javascript challenge

Posted: Sat Mar 25, 2006 8:19 pm
by rocknrisk
Hi all,

I have to mix PHP and Javascript... (not that I want to... I prefer not to use Javascript), and I'm unable to get a task to complete...

I need to open a popup window with a larger version of an image for a product.

In a PHP include (called by productdetail.php) file I have variable created from a MySQL query and echo a HTML line back to productdetail.php....

Code: Select all

...
$lnkLink = 'javascript:openpopup(\'bigpicture.php?strProductNumber='.$txtProductNumber.'\')';
...
...
echo '<a href="'.$lnkLink.'"><img src="images/pieces/set'.$numSet.'/'.$txtPicture.'/medium.jpg" width="150" height="150" border="0" align="top"></a></td>';
My JavaScript File (dfdjavascript.js) reads:

Code: Select all

<script type="text/javascript">

	function openpopup(popurl){
		var winpops=window.open(popurl,"","width=500px,height=500px");
	}

</script>
I also have the the "use javascript file" tag in the <head></head> of productdetail.php

Code: Select all

<script src="dfdjavascript.js" type="text/javascript"></script>
In the status bar I get "javascript:openpopup('bigpicture.php?strProductNumber=AAAAAA0001')" so I know that the php link code has echo'd properly.

I have also tested bigpicture.php by typing "bigpicture.php?strProductNumber=AAAAAA0001" into the address bar in IE and the page shows correctly, except not in a chromeless window as I want.

So, I conclude that the problem is with the Javascript. I don't know a lot about Javascript, so any ideas, PLEASE??? Maybe a type="" mismatch?

Also, is there a way to create a popup window with php? I really don't want to use JavaScript if I can help it.

Thank you in advance for any help.

Clinton

Posted: Sat Mar 25, 2006 8:25 pm
by feyd
try changing 500px to 500, the dimensions are in pixels already. As for creating a popup in PHP, no. But why not open the image in the page?

No go...

Posted: Sat Mar 25, 2006 8:35 pm
by rocknrisk
Hey feyd,

Thanks but no go. I still get "Done, but with errors on page", when
productdetail.php?strProductNumber=AAAAAA0001
loads.

Less code though :D

Clinton

Posted: Sat Mar 25, 2006 8:38 pm
by feyd
try removing the <script> tags from the external javascript file, they aren't needed, and can create errors. Although that likely won't solve it, but it may get rid of your error(s).

If you get errors still, post what the error says.

It works!!!

Posted: Sat Mar 25, 2006 9:44 pm
by rocknrisk
Nice one,

It now works...

Great JavaScript tip...

Thank you,
Clinton