in reply to Question about CGI and Javascript

You can do it with pure Perl, but you won't be able to create a popup window like in JavaScript. Rather, you send it to an initial CGI that grabs the list of stuff to be deleted, tells the user "are you sure about this?", with a "Yes, I am sure" button at the bottom. That button gives the data to a second CGI that does the actual deletion.

JavaScript will save you an extra server request each time. Also, you should be coding your pages in a such a way that you can still gain the benifits of JavaScript when its on in the browser, but won't stop you from using the web page if the browser has it shut off.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Question about CGI and Javascript
by shemp (Deacon) on May 13, 2003 at 19:36 UTC
    1) Learn how CGI.pm works. You can find information at CPAN. If nothing else, learn how to get at the form variables using CGI.pm. Lincoln Stein has published a great book on this subject. (he wrote CGI.pm)
    2) It sounds like you already know javascript. This should give you a good start on the DOM (document object module).
    3) Use javascript to set form variables on the client, then use those values in your perl cgi script to accomplish the proper goal.

    Here is a simple bit of logic to get you started.
    For instance, if you have 2 buttons, lets say OK and Cancel, both of which ultimately submit the form. Also, lets say you have a form varriable called button_pressed. To get your CGI to know which button was pressed, have your javascript onClick() handler for each button do whatever pre-submission action it needs to take, and also, have it set the value of button_pressed accordingly. Then, in your CGI script, just query the value of the button_pressed form variable.

    Note, there are other ways to accomplish this same thing, this is just one of them.
Re: Re: Question about CGI and Javascript
by AnneMarieK (Initiate) on May 13, 2003 at 18:07 UTC
    Thank you first. May I ask your expertise on how to do this? I recieved this project last week. How do I go about doing this. I was told that this could only be done in javascript. I'm sorry I am new to Perl, but excited to learn, especially since given the opportunity to learn.

      May I ask your expertise on how to do this?

      If you're willing to pay me for my time, sure :)

      Seriously, what I gave you above should get you started. The first CGI just needs to generate a form plus a "are you sure" message, and on confirmation, sends the list of stuff to be deleted to the second CGI, which does the actual work of deletion.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated