I'm a true novice in CGI so please bare with me.

Whom are we going to moon?

Ahem. Others have given you examples, but I think I can clarify the why of it a bit more...

A web form does not send the whole web page back to the script. That would be unnecessary, would waste bandwidth (and slow things down), and would create problems if a page has multiple forms (as is common; in some database-oriented CGI applications, a table may have a form on each line, with the ID of that record embedded in a hidden field, so that if the user clicks the "Edit" button on that line, he goes to a form for editing that record). In that case, how would the script know which form the user submitted?

So, to simplify matters, the web browser sends only the important information -- the name/value pairs from the form. In the case of select/option, the name comes from the select element and the value comes from the chosen option element. That's what value="foo" is for -- it sets the value that is sent back to the script. Whatever you put in there will be the value your script gets if the user chooses that option.

So, that's one reason it's convenient to have your script print the form itself; then it knows if a new option is added, or an option is reworded, or something. Your script might look like this (simplified) example...

%pet = ( fish.jpg => 'Fresh Fish', fido.jpg => 'Domestic Dog', ); if (getinput()) { print_header(); print "<body><p>I like $pet{$input{pet}}</p></body>"; print_footer(); } else { # no input; print the blank form... print_header(); print "<body><form method=\"post\" action=\"$ENV{REQUEST_URI}\"> Pet: <select name="pet">\n"; foreach $p (%pets) { print "<option value=\"$p\">$pet{$p}</option>\n"; } print "</select> <input type=\"submit\" value=\"submit\"> </form></body>"; print_footer(); }

The other option is to change your HTML form so that 'Fresh Water Fish' (or whatever) is the value.

 --jonadab


In reply to Re: Drop-down list Option Value by jonadab
in thread Drop-down list Option Value by Happyjack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.