Jump to content

[SOLVED] How can I open a popup window in php code?


jrod356a

Recommended Posts

Hi all,

 

I'm a PHP "Newbie" and am having trouble figuring out how to do the following:

 

I have a page with a form that contains radio buttons for each option available to the user to submit via a submit button.  The "form action" for the form is set to call a php script file (rpt_rdo_sel.php) when the submit button is clicked.  I am trying to have a popup window opened when the user selects one of a particular set of radio buttons (any of the last 3 radio buttons on the form).  The popup window is supposed to open and load an existing page located in my site's "dev/" directory.  Through my research on the web, I found sample code to do this as follows:

 

I made these entries in the rpt_rdo_sel.php file that is called when the submit button is clicked:

 

Add the javascript code before the "<?php" or after the "?>" tags (I chose to put it before):

 

<script type="javascript">

function openRequestedPopup()

{

  window.open('http://www.usedcarinteriors.com/dev/finadminlogin.php',

                  'FinanceAdminReportsLogin',

                  'width=545,height=326,resizable=yes,scrollbars=yes,status=yes');

}

</script>

 

 

Then add the following code within the PHP tags:

 

echo "<script type='javascript'>openRequestedPopup();</script>";

 

I then tested this by opening the form page in a browser window, I clicked one of the radio buttons that I designated for this function and clicked the submit button.  I then got a blank page and the popup window I expected did not open.  No errors were displayed on the resulting page however, I have FirePHP (a debugger tool) installed (I performed the test with FireFox) and I checked the output under the "Net" tab.  The "Post" values were correctly passed but the "Response" values reported show the javascript code and the php "echo" code I added in the .php file.  Now I'm not sure if my assumption is correct but I'm thinking that code may have been treated as comments text instead of program instructions and this is why all I'm getting is a blank page result?

 

Can anyone help me to get this working like I want it to?

Link to comment
Share on other sites

echo "<script type='javascript'>openRequestedPopup();</script>";

 

Why do you have this in the php page? Why not have an

onClick="javascript: openRequestedPopup;"

on the submit button or are you doing checking in the php page of whether to show the popup or not?

 

Also the <script type='javasscript'></script> tags are not needed around the function call. All you are doing is echoing the name of the function. You need to put it in an attribute eg <body onload=""> or onClick or onUnload etc.

 

Hope that helps.

Link to comment
Share on other sites

Hi All,

 

Thanks for your input.  The reason I'm adding this in a php file is because there is a condition that has to be met.  Let me clarify exactly what I'm trying to do here:

 

I'm trying to build a web form that based on the users radio button selection, runs a query and presents the results to the user as a report.  I have this part working fine.

 

The last 3 radio buttons on the form are for sales/admin specific reports that access should be limited only to management and supervisor so my solution to accomplish this without having to offer these report options on a separate page, etc., is to pop up a window with a login page that the user would have to logon to (thereby verifying their access rights to these features).  If login is successful, the will be allowed to proceed.  If not successful, an error message will be thrown and processing will be terminated.

 

Am I going about this in the wrong way?  Thanks for any guidance/input you can provide...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.