Jump to content

Recommended Posts

Hi Guys,

Not sure which section this thread should go to.

 

Probably a simple issue, but after staring @ the screen for long hours I just cant see it.

 

There are some pictures that are dynamically generated when the page is loaded. I have defined the width and height when they are loaded.

However, I would like a popup to appear once some clicks on the image showing the actual size of it.

 

I have written some javascript code and added the necessary modifications in my php code, but nothing appears when a value is passed to the javascript function, but the popup appears when nothing is passed. Probably a comma issue but I fail to see it.

 

Javascript Code

var newwindow;
function poptastic(url)
{
newwindow=window.open(url,'name','height=400,width=400');
if (window.focus) {newwindow.focus()}
}

 

PHP Code

	
$t = 'preview.php?it=' . $it;
echo "<a href='javascript:poptastic(".$t.");'><img src='$i1' height='100' width='100'/></a>  ";

 

If I run the below php code the popup works, but I can't pass any value to the javascript function.

		
//$t = 'preview.php?it=' . $it;
echo "<a href='javascript:poptastic();'><img src='$i1' height='100' width='100'/></a>  ";

Link to comment
https://forums.phpfreaks.com/topic/238657-php-javascript-popup-window/
Share on other sites

you are escaping your string when you try to add the t variable.:

echo "<a href='javascript:poptastic(".$t.");'><img src='$i1' height='100' width='100'/></a>  ";

should be:

echo "<a href='javascript:poptastic(\".$t.\");'><img src='$i1' height='100' width='100'/></a>  ";

I think gristoi is on the right track. When calling your poptastic() function, the URL argument needs to be surrounded by quotes. So you could use something like:

 

echo "<a href='javascript:poptastic(\"".$t."\");'><img src='$i1' height='100' width='100'/></a>  ";

 

 

Or:

 

echo "<a href='javascript:poptastic(\"$t\");'><img src='$i1' height='100' width='100'/></a>  ";

 

 

Note that I removed the dots from the second code example.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.