We help IT Professionals succeed at work.

Javascript popup, return to parent, close popup, run php program, passing a variable...

5,226 Views
Last Modified: 2013-11-19
Not sure if this has been answered but I couldn't find it, although some questions were along the same lines in some way.  In a nutshell:

User chooses menu option
Open a popup number keypad
Get a login id and pass that to a php program
Check a mysql database for security level
If cleared, close the popup
Return to parent
Run the called php program, passing along user id.

It all worked great until I decided to make the number keypad a popup.  Having problems getting back to parent and finishing the task list.

Parent window is a menu.  Contains popup function:

   <SCRIPT LANGUAGE="JavaScript">
   function popUp(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=245,height=355,left = 277,top = 122');");
   }
   </script>
   
When the user clicks menu item, I want to get a login id to check security access level for clearance.  The onclick pops up a number keypad whihc has been passed the name of the program to run if clearance is granted via mysql database as well as the calling program:

<div onclick="javascript:popUp('login.php?runprog=bomain.php&fromprog=index.php')">Back Office</div>


The login.php is a simple number keypad popup to allow user to enter a number.  When enter is pressed:

Calling:     <div Onclick="ChkAccess()">Enter</div>

function:
function ChkAccess()
{
   if (document.Login.Get_Logid.value != '0')
      window.location=''+ 'chkaccess.php?logid=' + document.Login.Get_Logid.value + '&runprog=<?php ECHO($liprogrun);?>'+ '&fromprog=<?php ECHO($lifromprog);?>' ;
}

ChkAccess.php snip that grants access:

        if ( $chksecreq <= $eseclvl ) {
           header("Location: $chkprogrun?logempid=$eempid");
           exit;
        } else {

This obviously opens the called program, passing along the user login code...

The problem is that I want the child-popup to return to the parent before opening the
called program.

I found the following JS on here and it sounded like it might do the trick, but alas, I was'nt sure where to put it and I wasn't at all sure of how to tell it to open the called program, passing along the user login code.  I presume my implementation is incorrect and/or the placement is incorrect, or I am simply way off base because I am a moron :) In over my head here. Can anyone show me the way?

Tried the following thinking it would return to parent and close the popup:

        if ( $chksecreq <= $eseclvl ) {
-->      <script>window.opener.location.reload(true);self.close();</script>
           header("Location: $chkprogrun?logempid=$eempid");
           exit;
        } else {...

Thanx a mil' for any help provided...
Owen
Comment
Watch Question

Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
try this

 if ( $chksecreq <= $eseclvl ) {
          echo("<html><head></head><body>");
          echo("<script>window.opener.location.reload(true);self.close();</script>");
          echo("</body></html>");          
          //header("Location: $chkprogrun?logempid=$eempid");
          exit;
        } else {...
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
and if you want to load  $chkprogrun?logempid=$eempid" in the parent try this

 if ( $chksecreq <= $eseclvl ) {
          echo("<html><head></head><body>");
          echo("<script>window.opener.location.href='".$chkprogrun?logempid=$eempid."'';self.close();</script>");
          echo("</body></html>");          

          exit;
        } else {...

Author

Commented:
Sorry kiranvj, same result.  Click button, runs login.php in a popup, get login id, runs chkaccess.php, then opens called program (in this case bomain.php in popup window.  Problem seems to lie in the fact that i really need to go back 2 programs

index.php --> logn.php --> chkaccess.php --> back to index.php, close popup, run new program

any way to hop back twice or will it be necessary to do it via some sort of variable passing scema?
Thanx so much for the effort.  It looked like it had teeth :)
Owen

Author

Commented:
Yes that's definitely the problem.  Chkaccess is dropping back to the popup whihc called it.  Is there a way to drop back to the original parent, or two children, so to speak?
Computer Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
kiranvj, that was peerfect.  It sure does help to have to think things thru to explain to another.  Thanx for that and the perfect syntax and positioning for the code :)
Owen
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
thanks Owen, your comment was a great motivation.
thanks once again for the points and grade and glad i could help you.

cheers,
kiranvj
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.