Jump to content

Archived

This topic is now archived and is closed to further replies.

masgas

pass php variable to popup

Recommended Posts

Hi! I want to pass the value of a mysql/php variable to a JavaScript pop up. The idea is, I show some information to the user, and if he wants to know more details, he can click on a link and open a popup where the info from the rest of the query I have in $result appears to him.

The popup function in the head area is:

function myPopup()

{
testpopup=window.open("popit.php","popit","status=0,height=200, width=400, menubar=0, resizable=0");
testpopup.moveTo(200,100);
}

And in the body area the code is this:
do {
echo "<tr><td border='1' align='center' ><form><a href='javascript:myPopup ()'><b>".$row["lexx"]."</b><input type='hidden' name='".$row["email"]."' value=".$row["email"]."</form></a></td></tr>";
}
while ($row = mysql_fetch_array($result));


The popit.php has a simple table like this:

<body>
<table width="100%"  border="0" cellpadding="0">
 <tr>
   <td>Nombre</td>
   <td>Apellido</td>
   <td>email</td>
   <td>Aeropuerto</td>
 </tr>
 <tr>
   <td><?php echo $Name; ?></td>
   <td><?php echo $Surname; ?></td>
   <td><?php echo $email; ?></td>
   <td><?php echo $lexx; ?></td>
 </tr>
 <tr>
   <td colspan="4">&nbsp;</td>
 </tr>
</table>


The result I get is an empty popup!

Any ideas what is wrong?

Share this post


Link to post
Share on other sites
Most conveniant way is to pass variables as GET, then you must adjust the javasript:

function myPopup(page)
{
testpopup=window.open(page,"popit","status=0,height=200, width=400, menubar=0, resizable=0");
testpopup.moveTo(200,100);
}

onclick="javascript: myPopup('popit.php?var=$var&morevar=$var2');"

Share this post


Link to post
Share on other sites
thank you!

I made the changes you said!

the code looks like this now:

echo "<tr><td border='1' align='center'><onclick='javascript: myPopup('popit.php?email=".$row["email"]."');><b>".$row["lexx"]."</b></a></td></tr>";

I don't get the popup! and no link either...  ???

Share this post


Link to post
Share on other sites
You where messing up with only single quotes around javascript, thats braking.

This:
[code]

echo "<tr><td border='1' align='center'><a onclick=\"javascript: myPopup('popit.php?email=".$row["email"]."');\">".$row["lexx"]."</a></td></tr>";

[/code]

Share this post


Link to post
Share on other sites
is the function declared correctly?

function myPopup("popit.php")
{
testpopup=window.open("popit.php","popit.php","status=0,height=200, width=400, menubar=0, resizable=0");
testpopup.moveTo(200,100);
}

Share this post


Link to post
Share on other sites
No - you are setting a permanent page.php inside it....

This works (undo the spaces in S C R I P T due to forum issue):
[code]

<s c r i p t language="javascript">

function myPopup(page)
{
testpopup=window.open(page,"CtrlWindow","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=400,height=200");
testpopup.moveTo(200,100);
}

</ s c r i p t>

<html>
<body>

<?php

$email = $row["email"];
$lexx = $row["lexx"];

echo <<<_HTML

<table><tr><td border='1' align='center'><a onclick="javascript: myPopup('popit.php?email=$email');">$lexx</a></td></tr></table>

_HTML;

?>

</body>
</html>

[/code]

Share this post


Link to post
Share on other sites

×

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.