Jump to content

pass php variable to popup


masgas

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?
Link to comment
https://forums.phpfreaks.com/topic/22399-pass-php-variable-to-popup/
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');"
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...  ???
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]

Archived

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

×
×
  • 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.