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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sharapov
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2003 11:11 pm

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

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
sharapov
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2003 11:11 pm

Post 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!!!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
Post Reply