SPUG: cgi method popup_menu
Lorraine Johnson
lorraine at nw.saic.com
Tue May 16 12:14:09 CDT 2000
Wild...it's true.
In the following code, I have three calls to popup_menu, the third form
element has the same name as the first. The third call to popup_menu
produces a different menu than the first. When the user clicks the Submit
button, one expects CGI.pm to only keep the second set. If I select
zucchini, pear, and peas, then the result gives me "zucchinipeas" for the
vegetable result. I guess you just don't want to use the same name twice
if you can help it. (Do you really need the space?)
Lorraine
##################################
This code:
##################################
#!perl -w
use strict;
use CGI qw(:standard :html3);
my $title = "Vegetables";
print header();
print start_html( -title=>$title, -bgcolor=>'#ffffff');
print h1($title), "\n";
if (!param()) {
print start_form(), "\n";
print popup_menu(-name=>'vegetable', -value=>[qw(okra squash zucchini
cauliflower)], -default=>'squash'), "\n<p>";
print popup_menu(-name=>'fruits', -value=>[qw(pear peach pineapple)],
-default=>'pineapple'), "\n<p>";
print popup_menu(-name=>'vegetable', -value=>[qw(beans peas carrots)],
-default=>'beans'), "\n<p>";
print submit(-name=>"Submit"), " ", reset(-name=>"Clear"), "\n";
print end_form();
}
else {
print "Vegetable is ", param('vegetable'), "\n<p>";
print "Fruit is ", param('fruits'), "\n<p>";
}
print end_html();
##################################
Produces this html:
##################################
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Vegetables</TITLE>
</HEAD><BODY BGCOLOR="#ffffff"><H1>Vegetables</H1>
<FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<SELECT NAME="vegetable">
<OPTION VALUE="okra">okra
<OPTION SELECTED VALUE="squash">squash
<OPTION VALUE="zucchini">zucchini
<OPTION VALUE="cauliflower">cauliflower
</SELECT>
<p><SELECT NAME="fruits">
<OPTION VALUE="pear">pear
<OPTION VALUE="peach">peach
<OPTION SELECTED VALUE="pineapple">pineapple
</SELECT>
<p><SELECT NAME="vegetable">
<OPTION SELECTED VALUE="beans">beans
<OPTION VALUE="peas">peas
<OPTION VALUE="carrots">carrots
</SELECT>
<p><INPUT TYPE="submit" NAME="Submit" VALUE="Submit"> <INPUT
TYPE="reset" VALUE="Clear">
</FORM></BODY></HTML>
##################################
Select zucchini, pear, and peas, and you get:
##################################
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Vegetables</TITLE>
</HEAD><BODY BGCOLOR="#ffffff"><H1>Vegetables</H1>
Vegetable is zucchinipeas
<p>Fruit is pear
<p></BODY></HTML>
##################################
At 11:18 PM 5/15/00 -0700, Joe Devlin wrote:
>If I make a call to the cgi method popup_menu more than
>once in a particular namespace it remembers the previous
>labels that were sent to it, then prints the previous popup_menu
>labels plus the new ones.
>
>I fixed the 'problem' by calling popup_menu inside a subroutine
>then passing the resulting text back to the calling routine.
>Apparently exiting the subroutine destroys the method.
>
>Is there a way to reuse the popup_menu without putting it
>in a subroutine?
>
>Joe
...................................
J. Lorraine Johnson
SAIC/Sea Technology
lorraine at nw.saic.com
v: (425) 482-3316
f: (425) 485-5566
http://www.nw.saic.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
For Subscriptions, Email to majordomo at pm.org: ACTION spug-list EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address
More information about the spug-list
mailing list