medalto has asked for the wisdom of the Perl Monks concerning the following question:

using CGI.pm I create radio buttons The fist one remains persistently highlighted. I've tried this to clear it ( ie start off with an empty form ) but it doesn't clear the button
my %vars = $q->Vars();#print Dumper %vars; $q->delete_all; print $q ->start_form; print $q->radio_group(-name=>'options', -values=>[keys %details] ,-col +umns => 4, -rows => 2);
this also has a button persistently selected that doesnt clear with a 'form reset'
foreach my $s (keys %details) {print "<input type=\"radio\" name=\"options\" value=".$s,">".$s." " +; }
but this doesn't
foreach my $s (@opts) {print "<input type=\"radio\" name=\"options\" value=".$s,">".$s." " +; }
so going back to the original
print $q->radio_group(-name=>'options', -values=>\@opts,columns => 4,- +rows> 2, -default=>'');
is there an explanation?

Replies are listed 'Best First'.
Re: clearing radio buttons
by scorpio17 (Canon) on Jan 22, 2010 at 18:14 UTC

    If you don't specify a default selection with the CHECKED attribute, the initial state is undefined - which means different browsers will do different things. Some will select the first item, others will select none, etc.

    For more details, read the specs

Re: clearing radio buttons
by ikegami (Patriarch) on Jan 22, 2010 at 18:34 UTC
    --override is needed?
      it isn't browser-specific. I've tried it in opera 10.01 and FF 3.5. When the page first loads , nothing is checked, but as soon as something is checked it is impossible to clear it ,using the CGI.pm constructor. not sure of --override syntax. the variations ive tried haven't made any difference.

        Honestly, what you are trying to do doesn't make much sense. A radio input is intended to select one of many. Not zero, not two. I'm not saying it's not possible, just that it wouldn't surprise me if it isn't.

        Why don't you add an extra button name "None" or similar.

Re: clearing radio buttons
by MidLifeXis (Monsignor) on Jan 22, 2010 at 18:03 UTC

    Perhaps the output from your snippets might help to find out what is going on. Have you tried to see what output is generated?

    It is said that "only perl can parse Perl." I don't even come close until my 3rd cup of coffee. --MidLifeXis