Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening modal window and passing variable to it to use in php code

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
Let's say I'm generating a modal window with the following code:


function doit(){

window.showModalDialog("index.php","","dialogHeight: 300px; dialogWidth: 300px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
}



and calling it with:

<button onclick=&quot;doit()&quot;>Test</button>


My question is: Is it possible to pass some variable to the new opened window (some number like ID for example) so that I can use this variable in the new opened page. (to run this number against database for example).

I know it can be done if I do something like index.php?id=1234, and then grab it with $_GET. But I'd rather have modal window. Can anybodu help?
 
sleipnir214,

I don't think you understood my question correctly. I am not using index.php as my source URL. I am using some other page from which I want to cal a function that would open index.php. Also I want to pass some variable into index.php so that I can use that variable to search MySQL database (for example).

I know that it is possible to pass variable to other page by doing <a href=&quot;index.php?id=1234&quot;> and then inside index.php use $_GET to get that variable, BUT I want to have MODAL window and not a regular one, and that is why I don't want to use that approach.
 
sleipnir214,

Thank you for your replyt. Don't stress out :). I found a solution to my problem. I can call this (Javascript) function like this:

<button onclick=&quot;doit('some_var')&quot;>Test</button>

the function itself looks like this:

function doit(myid){

window.showModalDialog(&quot;index.php?id=&quot;+myid,&quot;myid&quot;,&quot;dialogHeight: 300px; dialogWidth: 300px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;&quot;);
}

Then in index.php I can do something like:

if(isset($_GET['myid'])) {
echo &quot;Received parameter: &quot;.$_GET['myid'];
}else{
echo &quot;No param. ;(&quot;;
}

This would let me pass PHP variable from one page to the next using javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top