#!/bin/perl # # PROGRAM: popup_menu.cgi # # PURPOSE: Demonstrate (1) how to create a popup_menu form and # (2) how to determine the value selected by the user. # # Copyright DevDaily Interactive, Inc., 1998. All Rights Reserved. # #------------------------------# # 1. Create a new CGI object # #------------------------------# use CGI; $query = new CGI; #----------------------------------# # 2. Print the doctype statement # #----------------------------------# print $query->header; #----------------------------------------------------# # 3. Start the HTML doc, and give the page a title # #----------------------------------------------------# print $query->start_html('My popup_menu.cgi program'); #------------------------------------------------------------# # 4a. If the program is called without any params, print # # the popup_menu form. # #------------------------------------------------------------# if (!$query->param) { print $query->startform; print $query->h3('Select a dinner entree:'); print $query->popup_menu(-name=>'entrees', -values=>['Steak','Seafood','Veggies'], -default=>'Veggies'); #Note: You can specify an optional '-labels' parameter to # let the user see one value, while you use a different # parameter in your program. Using the '-labels' parameter, # your popup_menu might be defined like this: # #print $query->popup_menu(-name=>'entrees', # -values=>['Steak', # 'Seafood', # 'Veggies'], # -default=>'Veggies', # -labels=>{'Steak'=>'Filet Mignon', # 'Seafood'=>'Maui Maui', # 'Veggies'=>'Hand-picked vegetables'}); print $query->br; print $query->submit(-value=>'Select your meal'); print $query->endform; } else { #----------------------------------------------------------# # 4b. If the program is called with parameters, retrieve # # the 'entrees' parameter, assign it to a variable named # # $yourMeal, and then print it out. # #----------------------------------------------------------# print $query->h3('Looks like you ordered:'); $yourMeal = $query->param('entrees'); print "
\n"; print $yourMeal; print "
\n"; } #--------------------------------------------------# # 5. After either case above, end the HTML page. # #--------------------------------------------------# print $query->end_html;