Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Popup Message Box?

by mschnarr (Initiate)
on Nov 15, 2001 at 17:58 UTC ( #125561=perlquestion: print w/replies, xml ) Need Help??

mschnarr has asked for the wisdom of the Perl Monks concerning the following question:

Hey! I am running a CGI script and I'd like have a confirmation box pop up during loading and ask a yes/no question then have a specific variable set based on if they chose Yes or No. I tried doing this with win32::MsgBox but that didn't work. Any ideas? Thanks Matthew

Replies are listed 'Best First'.
Re: Popup Message Box?
by barndoor (Pilgrim) on Nov 15, 2001 at 18:16 UTC
    If you want to get a popup ok/cancel box appear on the browser then you will need to use javascript (have a look at the confirm() function).

    Your page would have to run a javascript function on loading to display the popup and then post back to your script with the users selection.

    You can't display a popup on a clients browser directly from CGI.
Re: Popup Message Box?
by {NULE} (Hermit) on Nov 15, 2001 at 18:16 UTC

    If you are talking about a Yes/No dialog lauched when someone hits a web page (as I presume if you are running CGI) you are limited to the browser's capability and having the launcher execute a Perl script probably isn't possible.

    Javascript (shudder) may be your friend here (who needs enemies?). Try something like this Untested:

    <SCRIPT LANGUAGE="JavaScript"> <!-- var test; test = confirm("Yes or no already"); document.write("test is set to: " + test); //--> </SCRIPT>

    Update: reformatted because of Opera's carriage return problem in UNIX.

    Good luck,

Re: Popup Message Box?
by jclovs (Sexton) on Nov 15, 2001 at 20:08 UTC
    Well, here is an example of what you could use:
    $q = new CGI; if(defined($q->param("confirm"))) { if($q->param("confirm") eq "yes"){ #execute code for yes } else { #execute code for no } } else { print $q->header(), "<html>\n", "<head>\n", "<script laguage\"JavaScript\">\n", "<!--\", "\"\", \"Confirm\",\"width=350, height=400, + toolbar=no menubar=no, scrollbars=no, resizeable=no\")\n", "popup.location.href=\"\n\", " = \"opener\", "// -->\n", "</script>\n", "</head>\n<body>", "</body></html>"; }
    Then your confirm.html page could look like this
    <html> <body> <form target="opener" action"location.of.script" method="post" o +nsubmit="window.close()"> <input type="radio" value="yes" name="confirm">Yes <input type="radio" value="no" name="confirm">No <input type="submit" value="submit" name="submit"> </form> </body> </html>
    Update: I'm not sure and I didn't feel like testing it right now but the onsubmit tage in the form might be slightly miss written. What might happen, unfortunately is that the window would close before the form got submitted. So instead of testing the code, I will offer an alt. so as to make my life easier. First delete the onsubmit attribute. Then put this code replace the perl ouput code to this:
    ... else { print $q->header(), "<html>\n", "<head>\n", "<script laguage\"JavaScript\">\n", "<!--\", "\"\", \"Confirm\",\"width=350, height=400, + toolbar=no menubar=no, scrollbars=no, resizeable=no\")\n", "popup.location.href=\"\n\", " = \"opener\", "// -->\n", "</script>\n", "</head>\n<body onunload=\"popup.close();\">", "</body></html>"; } ...
    P.S. this might just be a better all around solution.
    Clovs aka jclovs

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://125561]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2023-10-03 11:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found