I know this is a common question but I can’t find any answer.
I have a PHP file which contains a link. When that link is clicked, I want to open another page in a new window, and on this newly opened page I want to get the ID attribute of the link clicked on the previous page.
Current page= ‘patientreg.php’
Newpage to open in new window= ‘patient_history.php’
Post data from current page to new loaded page.
Current page Code:
HTML:
<a id="37" onclick="phistory(this.id);" href="#">View history</a>
JavaScript:
function phistory(myVar) {
var myurl = '../main/patient_history.php';
$.post(myurl,{data:myVar},function(){});
window.open(myurl,'_blank');
}
New page code:
$phid = $_REQUEST["data"];
echo phid;
The problem is that it is not echoing the data on the next page, but I can see echo with the full new page in the Firebug response tab of the current page.
try this, so using a form to send data to your page, and you can have more verbose the anchor element:
HTML:
Javascript:
Edit
if you need to open a new window for each story, you can create a new window with the name of the element id: