3

I have a page that is dynamically built by the database. For each thing that is built dynamically, I want to have a link that pops up a new window and that new window will populate a list from the database, based on which item on the first page was clicked. I have tried POST methods and posting the variable to the url (which I know is dangerous). The other thing that makes this unique is that the link that is clicked is really not a link to a page, but I do some Javascript to call a function that opens a new window and a new php page because it would be silly to open a whole new page for just a list. How do I do this? If you need more clarification I will do my best to make it clearer.

I am building a table and it will have links like this:

<td><a href="#" style="font-weight:normal; font-style:italic" onclick="function()">Do Stuff</a></td>

function function(){ window.open("page.php", "blank"," toolbar=no, width=400, height=350, top=50, left=50, scrollbars=yes"); }

The function() will open a new window with a new php page. The question is how to get the php variable over to the new window.

Chris
  • 145
  • 1
  • 3
  • 15

2 Answers2

5

simple ver

echo "<a href=\"#\" onclick=\"window.open('youPopUpPage.php?value=$value');\">link</a>";

into youPopUpPage.php

$value=$_GET["value"]; # retrive value from calling page

open with js function

<td><a href="#" style="font-weight:normal; font-style:italic" onclick="openPage(<?php echo $value ;?>)">Do Stuff</a></td>


<script type="text/javascript">
function openPage(value){
window.open('youPopUpPage.php?value='+value);}
</script>
Lucio Paoletti
  • 371
  • 2
  • 11
  • Thanks, this works perfectly! I am new to Javascript, and I actually wondered if this method was possible. Thanks a million, you are a gentleman and a scholar. – Chris Jun 03 '11 at 13:30
2

Make sure your just passing ID's that don't mean anything to anyone then do something like this with your links:

echo "<a href='/myaddress?id=".$id."'>my link</a>";

On the new window you will then be able to get to the value with get:

$id = mysql_real_escape_string($_GET['id']);

With this id you should be able to look in your database to find the actual content you want.

Matthew Riches
  • 2,298
  • 18
  • 26