elabuwa Posted June 7, 2011 Share Posted June 7, 2011 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> "; Quote Link to comment https://forums.phpfreaks.com/topic/238657-php-javascript-popup-window/ Share on other sites More sharing options...
gristoi Posted June 7, 2011 Share Posted June 7, 2011 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> "; Quote Link to comment https://forums.phpfreaks.com/topic/238657-php-javascript-popup-window/#findComment-1226419 Share on other sites More sharing options...
cyberRobot Posted June 7, 2011 Share Posted June 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238657-php-javascript-popup-window/#findComment-1226429 Share on other sites More sharing options...
elabuwa Posted June 7, 2011 Author Share Posted June 7, 2011 thank you guys. Worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/238657-php-javascript-popup-window/#findComment-1226463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.