Click here to get back home

CGI popup_menu does not change default selection

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
CGI popup_menu does not change default selection Yuri Shtil 03-24-2005
Posted by Yuri Shtil on March 24, 2005, 6:31 pm
Please log in for more thread options


Hi,

According to the doc, -default argument to popup_menu sets the default
selection.
It does not seem to work for me. I carefully examined the list of values and
the value of -default.
It seems to be OK, however the first choice is always selected. How can I
debug this problem?

Yuri.




Posted by Gunnar Hjalmarsson on March 25, 2005, 3:47 am
Please log in for more thread options


Yuri Shtil wrote:
> According to the doc, -default argument to popup_menu sets the default
> selection.
> It does not seem to work for me. I carefully examined the list of values and
> the value of -default.
> It seems to be OK, however the first choice is always selected. How can I
> debug this problem?

Considering the info you have provided, I'd suggest that you do it right
for a change and see if that makes a difference. ;-)

Seriously, what kind of answer would you expect when you don't show us
any code? You don't even say which module you have problems with!

Show us a *short* but *complete* script that people can copy and run,
and that illustrates your problem. If you do, somebody may be able to
give you some meaningful advice.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Posted by mbstevens on March 25, 2005, 4:05 am
Please log in for more thread options


Yuri Shtil wrote:

> Hi,
>
> According to the doc, -default argument to popup_menu
> sets the default selection.
> It does not seem to work for me. I carefully examined
> the list of values and the value of -default.
> It seems to be OK, however the first choice is always
> selected. How can I debug this problem?

CGI.pm is needed for safe CGI transactions.

The HTML writing functions are completely unnecessary,
however, and havn't kept up with changes at w3c;
start_html doesn't give you a doc type, for instance.
And, most are more complex to use than just writing the
HTML.

Just write your HTML in 'here' documents, or pull in
templates using one of the templating modules (cleaner).
A rudimentary templating system can even be done with
a couple of little subroutines as simple as this, if you
don't need anything fancy:

# Read, substitute, print to browser and close
sub dofile {
my $ff = shift;
open(XIN, "$ff") || err('open', $ff );
@dat = <XIN>;
make_substitutions @dat;
print "@datn";
close XIN || err('close', $ff );
}

# Substitute strings into commands in template data
sub make_substitutions {
foreach my $s (@_) {
$s =~ s/CGI_REPLACE_FNAME/$nm/eg;
$s =~ s/CGI_REPLACE_TITLE/$title/eg;
# and so on for whatever variables
# you might need to replace
# inside the template data.
}
}

Of course, for really simple programs, a 'here' document
is even simpler to use, so be sure to look up the details
on that.
--
mbstevens http://www.mbstevens.com/



Posted by Alan J. Flavell on March 25, 2005, 10:30 am
Please log in for more thread options


On Fri, 25 Mar 2005, mbstevens wrote:

> Yuri Shtil wrote:
>
> > According to the doc, -default argument to popup_menu
> > sets the default selection.
> > It does not seem to work for me. I carefully examined
> > the list of values and the value of -default.
> > It seems to be OK, however the first choice is always
> > selected. How can I debug this problem?
>
> CGI.pm is needed for safe CGI transactions.
>
> The HTML writing functions are completely unnecessary,
> however,

So, without even seeing the code that the original poster is using,
you're happy to tell him to make extensive changes to it? Methinks
you have a private agenda to pursue.

It might be more accurate to say that the HTML generating functions in
CGI.pm are optional accessories.

But you should beware of doing anything significant (e.g defining a
charset) without allowing CGI.pm to become aware of it.

> and havn't kept up with changes at w3c;

the version of CGI.pm that's distributed with Perl does tend to be
somewhat back-level compared to the latest version from L.Stein.

> start_html doesn't give you a doc type, for instance.

So in this online example:

http://stein.cshl.org/WWW/CGI/examples/tryit.cgi

you're trying to tell us that

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

in the generated source code was just a figment of my imagination?

There are some who would say that CGI.pm has moved ahead too fast in
the direction of w3c recommendations, since HTML/4.01 still has a
slight edge vis a vis support in currently deployed browsers, as
compared to the XHTML/1.0 Appendix C which Stein is generating by
default. But you can tell CGI.pm not to generate XHTML, if you like.

> And, most are more complex to use than just writing the HTML.

There are certainly other ways of generating the HTML. Which are more
or less complex depends on circumstances. If and when you decide to
move from HTML to XHTML (or indeed back again) it's a simple switch in
CGI.pm, but an error-prone editing job in Here documents.

> Just write your HTML in 'here' documents,

I'd say that's poor advice without even having seen the original
problem. In some simple cases it might be OK...

> or pull in templates using one of the templating modules (cleaner).

getting better, but still does not address the original problem...

> Of course, for really simple programs, a 'here' document
> is even simpler to use,

Using Here documents for generating the actual forms elements,
complete with values, defaults, sticky parameters etc. etc? I don't
think so. Even if you use Here documents or templates for the
surrounding HTML, I'd recommend using CGI.pm to generate the forms
elements.

Seems to me you're going to put the original poster to a fair bit of
effort *without* ever having diagnosed the actual problem.


Posted by Fabian Pilkowski on March 25, 2005, 4:24 am
Please log in for more thread options


* Yuri Shtil schrieb:
>
> According to the doc, -default argument to popup_menu sets the default
> selection.

Exact.

> It does not seem to work for me. I carefully examined the list of values and
> the value of -default.

Just an idea: try the script you'll find in the doc. For me (and my
browser firefox) it works.

> It seems to be OK, however the first choice is always selected. How can I
> debug this problem?

Have a look into the generated HTML code. Is thas correct, i.e. is the
"selected"-attribute of your <option>-tag set to a true value? If it is,
than have a look to another browser of your choice for testing.


#!/usr/bin/perl -w
use strict;
use CGI;
print CGI::popup_menu(
-name => 'menu_name',
-values => [ 'eenie', 'meenie', 'minie' ],
-default => 'meenie'
);
__END__


What this code is printing out for you? I think it's the same that I see
when executing here ... ;-)

regards,
fabian


Similar ThreadsPosted
words selection September 2, 2006, 10:43 am
[RFC] Money::PaymentPreparer - change sum to bills and coins December 29, 2004, 8:27 pm
Net::Telnet => Will cd ( change directory ) command work ? February 27, 2006, 3:44 am
Tips on module selection for shell and/or commandline 'subcommand' behavior January 16, 2007, 5:19 am
DB_File default version August 10, 2004, 4:24 pm
DateTime - default Timezone ? August 20, 2004, 2:21 pm
default location for apache2.pm October 3, 2005, 11:39 pm
IO::Socket default timeout September 25, 2006, 2:35 pm
changing $/ new line default character December 18, 2006, 11:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap