Clearing radio_group

Discussion in 'Perl' started by Nerfherder, Dec 14, 2004.

  1. Nerfherder

    Nerfherder Guest

    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();
    Nerfherder, Dec 14, 2004
    #1
    1. Advertising

  2. 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.
    Alan J. Flavell, Dec 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith

    Clearing values in WebControls

    John Smith, Jun 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    433
    John Smith
    Jun 29, 2003
  2. Dan
    Replies:
    0
    Views:
    443
  3. itsme

    Clearing session object contents

    itsme, Oct 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,578
    Steve C. Orr [MVP, MCSD]
    Oct 16, 2003
  4. GSK

    Clearing cached dlls

    GSK, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    331
  5. Patrick Kristiansen

    Clearing HTTPHandlers

    Patrick Kristiansen, Nov 1, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    John Saunders
    Nov 2, 2003
Loading...

Share This Page