Home > Archive > PERL Modules > December 2004 > Clearing radio_group
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Clearing radio_group
|
|
| Nerfherder 2004-12-18, 12:48 pm |
| I would like to be able to deselect a radio_group when the user selects
to clear the form.
#!/usr/local/bin/perl
use CGI qw(:standard);
$query = new CGI;
my $policy = "blank";
if( param( 'action' )) {
if( param( 'action' ) eq "Clear" ) {
$policy = "blank";
}
}
print header(), start_html(), start_form();
print radio_group( -NAME=>'level',
-VALUES=>[ 'Personal', 'Complete' ],
-LINEBREAK=>'true',
-DEFAULT=>$policy );
print br, $policy, br;
print br, submit( -NAME=>'action',
-VALUE=>'Clear' ), " ";
print end_form(), end_html();
| |
| Alan J. Flavell 2004-12-18, 12:48 pm |
|
Crossposting to a long-since deceased newsgroup isn't recommended.
Followups set.
On Tue, 14 Dec 2004, Nerfherder wrote:
> I would like to be able to deselect a radio_group
That's a logical impossibility. A radio group is defined by the fact
that exactly one of the buttons is always selected. Any client
implementation which doesn't do that could be described as buggy.
That has nothing to do with Perl nor with CGI.pm: it's a fact of
the HTML specification.
If you want a radio button option which means "user hasn't made a
selection", then you need a third radio button for it, and select that
as the default.[1]
> #!/usr/local/bin/perl
>
> use CGI qw(:standard);
> $query = new CGI;
I'd recommend using strict and warnings. In a CGI context, the -T
(taint checks) option is strongly recommended too, as a safety belt.
[1] this might help, though - as I say - it has nothing to do with
Perl as such: http://ppewww.ph.gla.ac.uk/~flavell/www/testradio.html
It may well be that your chosen browser can do what you reckon you
wanted; but the HTML specification still says what it says. I'd say
design within its constraints.
| |
| Mitja 2004-12-18, 12:48 pm |
| On Wed, 15 Dec 2004 00:09:07 +0000, Alan J. Flavell <flavell@ph.gla.ac.uk>
wrote:
>
> Crossposting to a long-since deceased newsgroup isn't recommended.
> Followups set.
>
> On Tue, 14 Dec 2004, Nerfherder wrote:
>
>
> That's a logical impossibility. A radio group is defined by the fact
> that exactly one of the buttons is always selected. Any client
> implementation which doesn't do that could be described as buggy.
>
> That has nothing to do with Perl nor with CGI.pm: it's a fact of
> the HTML specification.
Um, in fact:
http://www.w3.org/TR/REC-html40/int...orms.html#radio
And IIRC both Opera and IE 6 support radio groups woth no selected
elements, though it does seem unlogical. A paragraph virtually identical
to the one I linked to above can be found a bit further down the page
concerning the SELECT element and its OPTIONs. For those, I am positive
that most browsers (at least IE, Opera, Mozilla) behave in the way you
consider buggy.
--
Mitja
| |
|
| On Wed, 15 Dec 2004 00:09:07 +0000, Alan J. Flavell <flavell@ph.gla.ac.uk>
wrote:
>
> Crossposting to a long-since deceased newsgroup isn't recommended.
> Followups set.
>
> On Tue, 14 Dec 2004, Nerfherder wrote:
>
>
> That's a logical impossibility. A radio group is defined by the fact
> that exactly one of the buttons is always selected. Any client
> implementation which doesn't do that could be described as buggy.
>
> That has nothing to do with Perl nor with CGI.pm: it's a fact of
> the HTML specification.
Um, in fact:
http://www.w3.org/TR/REC-html40/int...orms.html#radio
And IIRC both Opera and IE 6 support radio groups woth no selected
elements, though it does seem unlogical. A paragraph virtually identical
to the one I linked to above can be found a bit further down the page
concerning the SELECT element and its OPTIONs. For those, I am positive
that most browsers (at least IE, Opera, Mozilla) behave in the way you
consider buggy.
--
Mitja
| |
| Alan J. Flavell 2004-12-20, 3:56 pm |
| On Thu, 16 Dec 2004, Mitja wrote:
>
> Um, in fact:
> http://www.w3.org/TR/REC-html40/int...orms.html#radio
I know - it concludes with what I considered to be good advice:
| Since user agent behavior differs, authors should ensure that in
| each set of radio buttons that one is initially "on".
> For those, I am positive that most browsers (at least
> IE, Opera, Mozilla) behave in the way you consider buggy.
Alright, I said "could be described as buggy" - and so it could,
relative to the RFC. As far as HTML4 is concerned, the behaviour is
only "undefined". So sue me...
If you're so desperately keen to ignore the W3C's advice, in favour of
doing experiments on a few browsers, then it's up to you. Have fun.
|
|
|
|
|