in reply to Drop-down list Option Value
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
|
|---|