Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7506

Re: Syntax for resetting radio button to initial value?

Message-ID <1768275.D2KPVSPYKU@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2011-10-17 14:32 +0200
Subject Re: Syntax for resetting radio button to initial value?
Newsgroups comp.lang.javascript
References <j7fhjv$btu$1@dont-email.me> <4e9c09f5$0$28616$a8266bb1@newsreader.readnews.com>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Denis McMahon wrote:

> On Sun, 16 Oct 2011 23:16:48 +0200, Garry Jones wrote:
>> I have a reset function for a user form which clears text fields, resets
>> drop down boxes to initial values and moves focus to first input field.
>> However I need to reset radio buttons to their inital value (of zero).
> 
> Radio buttons shouldn't have an initial value of zero.

What would be the reason for that?
 
> A radio group is a group of buttons of which one and only one is
> selected. This is the default option for the group, and should be marked
> as such, eg:
> 
> <form>
> <input type="radio" value="1" name="music"> Classical<br>
> <input type="radio" value="2" name="music"> Jazz<br>
> <input type="radio" value="3" name="music" checked="checked"> Rock<br>
> <input type="submit"><input type="reset">
> </form>

That's HTML5 at most.  But imagine what would happen if you simply omitted 
the `checked' attribute.  It's optional, you know.
 
BTW, including a reset button in a form is almost always a stupid idea:
<http://www.useit.com/alertbox/20000416.html>

> If I don't want the default option to be visible for a radio button set,
> what I usually do is something like this:
> 
> <form>
> <input type="radio" value="0" name="music" checked="checked"
> style="display:none">
> <input type="radio" value="1" name="music"> Classical<br>
> <input type="radio" value="2" name="music"> Jazz<br>
> <input type="radio" value="3" name="music"> Rock<br>
> <input type="submit"><input type="reset">
> </form>
> 
> Now a value of "0" means "none of the visible options was selected".

Works great with and without CSS.  NOT.  It's complete utter nonsense; don't 
*ever* do this.  If you don't pre-check any radiobutton of a radiobutton 
group, it will not be part of the request.  There is absolutely no need
to transmit a "hidden" default value for a radiobutton group.

Not that this code would have *anything* to do with the OP's question.
 
> It may be that the latter is a solution to your problem too.

It does not even address the problem.  Would you *please* get a minimum clue 
before making suggestions.


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Syntax for resetting radio button to initial value? "Garry Jones" <garry@garryjones.se> - 2011-10-16 23:16 +0200
  Re: Syntax for resetting radio button to initial value? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-10-17 00:46 +0300
    Re: Syntax for resetting radio button to initial value? dhtml <dhtmlkitchen@gmail.com> - 2011-10-16 22:56 -0700
  Re: Syntax for resetting radio button to initial value? Matt McDonald <matt@fortybelow.ca> - 2011-10-16 16:49 -0600
    Re: Syntax for resetting radio button to initial value? dhtml <dhtmlkitchen@gmail.com> - 2011-10-16 22:57 -0700
    Re: Syntax for resetting radio button to initial value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-17 09:56 +0200
  Re: Syntax for resetting radio button to initial value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-17 09:51 +0200
  Re: Syntax for resetting radio button to initial value? Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-17 10:56 +0000
    Re: Syntax for resetting radio button to initial value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-17 14:32 +0200
  Re: Syntax for resetting radio button to initial value? Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-17 11:16 +0000
    Re: Syntax for resetting radio button to initial value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-17 14:45 +0200
    Re: Syntax for resetting radio button to initial value? "Garry Jones" <garry@garryjones.se> - 2011-10-17 20:31 +0200
      Re: Syntax for resetting radio button to initial value? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-18 10:45 +0200
  Re: Syntax for resetting radio button to initial value? Dr J R Stockton <reply1142@merlyn.demon.co.uk> - 2011-10-18 20:50 +0100

csiph-web