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


Groups > comp.lang.javascript > #7504

Re: Syntax for resetting radio button to initial value?

From Denis McMahon <denismfmcmahon@gmail.com>
Subject Re: Syntax for resetting radio button to initial value?
Newsgroups comp.lang.javascript
References <j7fhjv$btu$1@dont-email.me>
Date 2011-10-17 10:56 +0000
Message-ID <4e9c09f5$0$28616$a8266bb1@newsreader.readnews.com> (permalink)
Organization readnews.com - News for Geeks and ISPs

Show all headers | View raw


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.

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>

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".

It may be that the latter is a solution to your problem too.

Rgds

Denis McMahon

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