Mixed PHP and Javascript challenge

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
rocknrisk
Forum Newbie
Posts: 16
Joined: Tue Mar 14, 2006 8:09 pm

Mixed PHP and Javascript challenge

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
rocknrisk
Forum Newbie
Posts: 16
Joined: Tue Mar 14, 2006 8:09 pm

No go...

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
rocknrisk
Forum Newbie
Posts: 16
Joined: Tue Mar 14, 2006 8:09 pm

It works!!!

Post by rocknrisk »

Nice one,

It now works...

Great JavaScript tip...

Thank you,
Clinton
Post Reply