in reply to Re: Drop-down list Option Value
in thread Drop-down list Option Value

Easiest way to do that is just use a hash mapping the whatever.gif|jpg to the text values. You use hashes in your program already so I guess you don't need an explanation of how to use them. :)

Note: untested code follows:

#!/usr/bin/perl -w require "cgi-lib.pl"; &ReadParse; my %hashOfAnimals = ( "pets.gif" => "Your Favorite Pet", "afghanhd.jpg" => "Big dogs", "austter.jpg" => "Little dogs", "ragdoll2.jpg" => "Cats", "fish1.jpg" => "Fresh water fish", "gerbil.jpg" => "Gerbils", "morganhorse.jpg" => "Horses", "parrot.jpg" => "Parrots", "macaw.jpg" => "Macaws", "toucan.jpg" => "Toucans", "snap.jpg" => "Turtles", "iguana.jpg" => "Iguanas", "sinaloan.jpg" => "Snakes" ); #color.cgi #Warn browser that HTML is coming print &PrintHeader; print <<"eohtml"; <html><head><title>Thanks for responding</title></head> <body bgcolor = "#FFFFFF"><H1>Thank You</H1> <p>What a coincidence, $in{'firstname'} $in{'lastname'}!!</p> <p>My favorite color is $in{'color'} <strong>AND</strong> I Love $hash +OfAnimals{$in{'pet'}}.</p> </body></html> eohtml #End of Program


Updated: Forgot if key has . in it, key needs to be quoted. Doh!

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: Re: Drop-down list Option Value
by Happyjack (Novice) on Feb 02, 2003 at 19:58 UTC

    Antirice,
    Thanks for your help. The code required only one simple change; it requires that the jgp/gif option values be enclosed in quotation marks (as well as the descriptions). With thism change, the code worked perfectly.

    Now I would like to expand this cgi code to display the selected image from the HTML file. This may, in fact, be much more advanced than I am right now. However, it's all a learning experience. Any suggestions in displaying the selected image?

    THX!!!

      Well even I can do this one :)
      print <<"eohtml"; <html><head><title>Thanks for responding</title></head> <body bgcolor = "#FFFFFF"><H1>Thank You</H1> <p>What a coincidence, $in{'firstname'} $in{'lastname'}!!</p> <p>My favorite color is $in{'color'} <strong>AND</strong> I Love $hash +OfAnimals{$in{'pet'}}.</p> <p><center><img src="$in{'pet'}"></center></p> </body></html> eohtml
      Just change the above snippet. You might want to add image attributes and other formatting.