Page 1 of 1

Opening modal window and passing variable to it to use in ph

Posted: Wed Nov 19, 2003 7:21 pm
by sharapov
Let's say I'm generating a modal window with the following code:

Code: Select all

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:

Code: Select all

<button onclick="doit()">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 MySQL 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?

Posted: Wed Nov 19, 2003 7:38 pm
by Weirdan

Code: Select all

function doit(some_var)&#123; 

window.showModalDialog("index.php?some_var="+some_var,"","dialogHeight: 300px; dialogWidth: 300px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;"); 
&#125;

Code: Select all

if(isset($_GET['some_var'])) {
  echo "Received parameter: ".$_GET['some_var'];
}else{
  echo "No param. ;(";
}
It will open modal window and pass the some_var to it.

Posted: Wed Nov 19, 2003 7:45 pm
by sharapov
Weirdan,

Very interesting approach. I haven't tried it yet, but it looks like it just might work.

Thank you for your help!!!

Posted: Wed Nov 19, 2003 8:24 pm
by Weirdan
you can even try:

Code: Select all

function do_it()&#123;
  var qstr="";
  for(var in arguments)&#123;
    if(qstr.length) qstr+="+";
    qstr+=var;
  &#125;
 window.showModalDialog("index.php?"+qstr,.............);
&#125;

.... onclick="do_it('1st',2,'third','some other param')".....
and then retreive the parameters using $argv array:

Code: Select all

foreach($argv as $arg)
  echo "Got param: $arg\n";
You can pass the arbitrary number of parameters this way, but you can't name they.