[prog] Popup in PHP or Javascript

Julie Bovee Hill joulie at gmail.com
Mon Apr 10 11:59:17 EST 2006


On 4/9/06, Tiera wrote:
>
> The second php script should open in the pop-up. So step 4 and 5 should be:
>
> 4. result data is sent of to another php script that is opened in a
> pop-up window and displays the result there.
>

I can't think of a way to do what you're wanting without Javascript,
but I don't think it has to get really complicated, either. My
Javascript is pretty outdated, but I think that you should be able to
do something like this:

1. user fills out form
2. user clicks a button that does not POST data but instead invokes
some Javascript (avoids the page re-load)
3. through some tricky Ajax-type Javascript a request is made to the
server to do the calculation and read back the result
4. the Javascript then opens a popup window that has the URL of the
second php script and passes any relevant data from the first server
calculation in the query string
5. result loads into the popup
If #4 must be a POST and not a GET, then your <form> needs to be
defined with target being set to the child window. A GET request would
be the simpler option.

A simpler alternative that should also work but requires the page reload:

1. user fills out form
2. user clicks a button that POSTs data to 1st php script
3. server sends back result
4. as the original page reloads, an onLoad event in the <body> tag
invokes Javascript that opens a popup with the URL of the 2nd php
script (a GET) with necessary data from 1st POST in the query string
5. popup loads with result page from 2nd php script

As I recall, loading pop-ups with non-static result data is
hazard-prone, but everyone does it anyway. Keep in mind that the
server could hang or timeout and nothing loads into your popup, or you
can have the thrill of seeing a server error page all scrunched up
inside of your popup, etc., so code defensively with lots of error
condition checking to avoid embarassment.

There a quite a few Ajax libraries out there that do the most
complicated Javascript stuff for you. Here are a couple of links I
begged off my S.O. who's more knowledgeable about Javascript/Ajax
things than I am these days (but neither of us are experts). I hope
they help:

http://www.litfuel.net/mybic/index.html?page=index
http://www.modernmethod.com/sajax/index.phtml

Julie


More information about the Programming mailing list