Clearing radio_group

N

Nerfherder

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();
 
A

Alan J. Flavell

Crossposting to a long-since deceased newsgroup isn't recommended.
Followups set.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top