Passing parramter from php to javascript back to php
I have a php page that uses javascript to create a popup that contains another php page. The php page in the popup is basically a form and will use this value to insert into the database. Using the following function to load php page in popup:
phppopup('edit_status.php?cmd=EditStatusData')
function phppopup(page){
child1 = window.open (page, "Ebay Auctions", "height=600,width=600,status=yes,toolbar=no,menubar=no,location=no");
child1.document.close();
}
How do I pass a value from the calling page to the page in the popup?
I am trying at the moment:
echo "<p><a href=\"#\" onclick=\"updateByEdit('". $username ."', '". $subcat ."')\">Edit User Info</a>
<p><a href='#' onclick=\"makewindows2('edit_status.php?cmd=EditStatusData&pk=". $pk ."'); return false;\">Historie</a>;
Which generates the following html:
<a href="#" onclick="updateByEdit('trendsandbrands', 'fakeapproved')">Edit User Info</a>
</strong></strong></strong></strong></p><p><strong><strong><strong><strong><a href="#" onclick="phppopup('edit_status.php?cmd=EditStatusData&pk='); return false;">Historie</a>
It works fine for updateByEdit, why not phpopup?
$ pk is just an integer that displays fine on the page from which the window is called.
a source to share
Just add the arguments as part of the get request:
phppopup("index.php?var1=value1&var2=value2"); // Get
etc..
Alternatively, to pass its arguments when it's already open, use the return handle (child1) and access that window DOM via javascript.
child1.document.getElementById("myelement").innerHTML = "Hello World"; // Parent Child
If you are having trouble with this, ask the child window to call a callback on the parent window via window.opener when the child document is loaded, for example
window.opener.myCallback(requestedinfo); // Parent window callback function
a source to share