Jump to content


Photo

pass php variable to popup


  • Please log in to reply
8 replies to this topic

#1 masgas

masgas
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 28 September 2006 - 05:47 PM

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?

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 05:53 PM

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');"

#3 masgas

masgas
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 28 September 2006 - 06:29 PM

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...  ???

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 06:36 PM

You where messing up with only single quotes around javascript, thats braking.

This:

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



#5 masgas

masgas
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 28 September 2006 - 07:23 PM

thanks, link appears but no luck with pop up!
:-\

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 07:29 PM

do you have a link to it for us to see ?

#7 masgas

masgas
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 28 September 2006 - 07:39 PM

I'm working in local...

#8 masgas

masgas
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 28 September 2006 - 07:40 PM

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);
}

#9 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 08:05 PM

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):

<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>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users