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

Hello,

I'm very new to the concept of writting a CGI. I've programmed in a few other languages and started learning pearl several months ago, however I have never messed with HTML before.

Anyways I am wanting to write a script that will have several menus each with various selections of positive and negitive numbers. The script should perform the math on the numbers and print the total in a box below them. I'm wanting this to be a dynamic document. If the user changes one of the menu options it will submit that new option perform the math and print the new result.

So far I think I've solved and learned most of how to do this. The main problem I'm currently having is I cant figure out how to get the menu to submit its new value without making a submit button. I have seen people do it other ways and I was wondering how to do that with CGI.pm.

The next area I might have fun trying to play with is keeping state in this document. I saw that CGI.pm gives me some ways to do this but I wasnt the most clear on how.

If anyone of the kind folks here can give me some advice on my main problem or on my script in general it would be wonderful.

Replies are listed 'Best First'.
Re: CGI Menu submit
by simonm (Vicar) on Dec 27, 2003 at 22:41 UTC
    I cant figure out how to get the menu to submit its new value without making a submit button.

    The HTML tag for the "menu" (more properly called a popup or dropdown select box) needs to have the following attribute added: onchange="this.form.submit()".

Re: CGI Menu submit
by Cody Pendant (Prior) on Dec 27, 2003 at 23:53 UTC
    The reason you can't figure it out is because it's a JavaScript question, not a Perl question.

    JavaScript is a client-side language, which can control the browser. Perl is the server-side language which, when told to do so by the browser, will do the math and send back the result.

    How does your interface work, by the way? Can any of your menus make the form submit? If I want to do two plus two equals four, do I have to select two, have the form submit, select plus, have the form submit, select two again and have the form submit a third time? That's going to drive me crazy...



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
Re: CGI Menu submit
by chanio (Priest) on Dec 28, 2003 at 16:12 UTC
    There are two ways of receiving requests in a CGI script:
    • by GET : http://your.address/cgi-bin/yourscript.pl?field1='value1';field2='another value' , or by form submit
    • by POST: all the variables where assigned at a form that submits by POST to your cgi.script (the values are invisible at the address)

    You can read this on-line book: Perl for the Web by Chris Radcliff , find more info about the server - environment variables (how to use them).

    The module that you need to learn about is CGI.pm, read something simple as: a tutorial of CGI::Application for beginers, as a starting. But it is not even the peak of the iceberg :) .