homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

PHP and Javascript help
Passing a PHP variable to a Javascript popup. How?

 12:33 am on May 4, 2006 (gmt 0)

Here's an easy one, or at least I think it should be.

I need to pass a php variable to a pop-up opened using javascript.

$picone1 is a pic name ramdomly selected from a mysql database, I then use $picone1 to display a thumbnail pic which is a link to a pop up page which shows a larger version of that pic.

Here's what I have on the main page;
<a href=# onclick=window.open('viewpic.php?piconel','newpage',width=350,height=350'); return false> </a>

On viewpic.php, I simply have this;
<img src=$piconel>

I'm sure it's probably a tad more complicated then that. It's not working, and any help would be much appreciated



 12:42 am on May 4, 2006 (gmt 0)

Welcome to WebmasterWorld RichtorScript,

if I understand correctly you could use php to write the link

<a href=# onclick=window.open('viewpic.php?<?php echo $picone1;?>','newpage',width=350,height=350'); return false> </a>

I think that is what you mean

<added>I notice you use both $piconel and $picone1 are they different vars?


 5:12 am on May 4, 2006 (gmt 0)

Hey, thanks for the welcome!
And of course thanks for your help.

So I got it to work on a test page, but when I try to implement it on the actual page, which randomly selects 4 pics and displays them, it doesn't seem to work. I think this is because I'm using it in between an echo statment. Here's what I'm looking at.

$random = mt_rand(0,$row-1)+1;
while(in_array($random,$randomNumbers)) {
$random = mt_rand(0,$row-1)+1;
if ($result){
while ($r = mysql_fetch_array($result)) {
if ($i == 0 AND $r[index] == $random){
$picone = $r["spic"];
$piconel = $r["lpic"];
echo "
<div id=pic1> <a href=# onclick=window.open('viewpic.php?piconel=<?php echo $piconel;?>','CSPL','width=350,height=350'); return false>
<img src= $picone width=86 height=71></a>
}else if ($i == 1 AND $r[index] == $random){
$pictwo = $r["spic"];
echo "
<div id=pic2>
<img src= $pictwo width=86 height=71>
}else if ($i == 2 AND $r[index] == $random){
$picthree = $r["spic"];
echo "
<div id=pic3>
<img src= $pic3 width=86 height=71>
}else if ($i == 3 AND $r[index] == $random){
$picfour = $r["spic"];
echo "
<div id=pic4>
<img src= $picfour width=86 height=71>
echo "No data";
Is there a work around or a better way to set it up?


 7:09 am on May 4, 2006 (gmt 0)

hi RichtorScript,

does your script on the other-then-test system returns your "no data" message?

if so, your database request is not working.

if not, please tell with more detail, what does your script output and where the problem is. it might be within the viewpic.php for example. it might be that the php configuration between your test and life system differ (register globals for example) and that's why it is not working etc. so please some more info to track down the problem.



 4:35 pm on May 4, 2006 (gmt 0)

Thanks for the help, but I got that part figured out. As far as I can tell it was becuase I using a <?PHP?> call in the middle of a an echo statement. As soon as I took it out and worked.

Now another question, can I send two variables this is what I was trying;

<a href="#" onclick="window.open('viewpic.php?piconel=<?php echo $piconel;?>?pic1text=<?php echo $pic1text;?>','newpage','width=350,height=350'); return false">
<img src= "pic.jpg" width=86 height=71>


 5:06 pm on May 4, 2006 (gmt 0)

>> can I send two variables

yes, what you have there should work

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved