[PLUG] Perl / Javascript question

Jeff Schwaber freyley at gmx.net
Wed Sep 17 12:03:01 UTC 2003


On Wed, 2003-09-17 at 09:37, Daggett, Steve wrote:
> Matt Alexander queried:
> > I have a Javascript popup window where the user chooses some 
> > settings and
> > then clicks submit.  After submitting, the form vars are sent 
> > to a perl
> > script that saves the vars as cookies on the user's box.  I 
> > would like the
> > popup window to close when they click submit, so I added
> > onsubmit="window.close()", but when I do this the cookies are 
> > no longer
> > set.  It's as if the window is closed before the perl script 
> > is called. 
> > Any suggestions on how to fix this?  I know I could just set 
> > the cookies
> > with Javascript, but I'm curious about how to make this way work.
> 
>   Cookies are browser based.  You'll need to set the cookie value in the
> browser before you submit the form.  The current cookie values are sent to
> the CGI script with the HTTP GET.  You can't set the values after the
> submit.  It's too late.
> 
>   I had a similar situation with a little web app I recently wrote.  I was
> using cookies to maintain state information about the display pages.  The
> cookie *has* to be set before submit so the CGI script receives the correct
> cookie values.  I tried a bunch different techniques.  I finally used
> Javascript to get it working correctly. 
> 
> Steve D...

There's a slight difference between the cases: he's talking about the
perl script setting the cookies (which it can do) before going on to do
other things. You're talking about a submit box to a script which needs
the cookies already set. If they have to _already_ be set by the time
the script acts, then you need javascript (or an intervening script). If
they are set by this particular script (it sounds likely that this is an
intermediary script specifically for setting cookies, since it's in a
popup window) then it can be set by perl or by javascript. If it's set
by javascript, it doesn't even need to send anything to the server, and
you might be able to do it with a java applet, instead. But in either
case, they're different situations.

Jeff





More information about the PLUG mailing list