homepage Welcome to WebmasterWorld Guest from 54.197.147.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
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?
RichtorScript




msg:1247628
 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

 

jatar_k




msg:1247629
 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?

RichtorScript




msg:1247630
 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;
}
array_push($randomNumbers,$random);
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>
</div>";
}else if ($i == 1 AND $r[index] == $random){
$pictwo = $r["spic"];
echo "
<div id=pic2>
<img src= $pictwo width=86 height=71>
</div>";
}else if ($i == 2 AND $r[index] == $random){
$picthree = $r["spic"];
echo "
<div id=pic3>
<img src= $pic3 width=86 height=71>
</div>";
}else if ($i == 3 AND $r[index] == $random){
$picfour = $r["spic"];
echo "
<div id=pic4>
<img src= $picfour width=86 height=71>
</div>
";
}}
mysql_free_result($result);
}else{
echo "No data";
}
Is there a work around or a better way to set it up?

hakre




msg:1247631
 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.

--hakre

RichtorScript




msg:1247632
 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>
</a>

jatar_k




msg:1247633
 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