473,508 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function to unselect radio buttons

I use window.document.form1.myCheckbox.checked=false;
to uncheck (reset) several checkboxes. What is an equivalent for resetting
a set of interrelated radio boxes?

--
Ed Jay (remove M to respond by email)
Nov 24 '05 #1
4 19420
Ed Jay wrote:
I use window.document.form1.myCheckbox.checked=false;
to uncheck (reset) several checkboxes. What is an equivalent for resetting
a set of interrelated radio boxes?


Not quite sure what you mean by 'a set of interrelated radio boxes'.

I'll guess that you mean a set of radio buttons that all share the same
name ('myCheckbox' in your example) and that 'resetting' means return
them to their default state when the page loaded.

The trivial answer is if they are in a form, reset the form. If they
aren't, or you want to reset just the set of buttons, loop through them
and set their checked property to their 'defaultChecked' property:
var cBoxes = document.form1.myCheckbox;
for(var i=0, n=cBoxes.length; i<n; ++i){
cBoxes[i].checked = cBoxes[i].defaultChecked;
}
As a matter of interest, opinion is divided on whether one radio button
should always be checked - the relevant part of the HTML spec says that:

"...authors should ensure that in each set of radio buttons that
one is initially 'on'."

<URL: http://www.w3.org/TR/html4/interact/forms.html#radio >
--
Rob
Nov 24 '05 #2
RobG <rg***@iinet.net.au> wrote:
Ed Jay wrote:
I use window.document.form1.myCheckbox.checked=false;
to uncheck (reset) several checkboxes. What is an equivalent for resetting
a set of interrelated radio boxes?
Not quite sure what you mean by 'a set of interrelated radio boxes'.

I'll guess that you mean a set of radio buttons that all share the same
name ('myCheckbox' in your example) and that 'resetting' means return
them to their default state when the page loaded.


Yes.
The trivial answer is if they are in a form, reset the form. If they
aren't, or you want to reset just the set of buttons, loop through them
and set their checked property to their 'defaultChecked' property:
The form is several pages long, with each page loaded from a Perl script.
I'm passing variables from page to page by submitting them as hidden input
form elements.
var cBoxes = document.form1.myCheckbox;
for(var i=0, n=cBoxes.length; i<n; ++i){
cBoxes[i].checked = cBoxes[i].defaultChecked;
} Does document.form1.reset() reset the hidden input elements as well?
As a matter of interest, opinion is divided on whether one radio button
should always be checked - the relevant part of the HTML spec says that:

"...authors should ensure that in each set of radio buttons that
one is initially 'on'."

<URL: http://www.w3.org/TR/html4/interact/forms.html#radio >


Point well taken. How about a reset button as default. That's what I just
did. :-)

Looping through selected elements appears to be the best way to go.

--
Ed Jay (remove M to respond by email)
Nov 24 '05 #3
Ed Jay wrote:

[...]
Does document.form1.reset() reset the hidden input elements as well?


In IE, yes. In Firefox, no. calling the form's reset method is the
same as clicking on a rest button in the form (as far as I can tell).

My reading of the spec is that the values should be reset to their
initial value, so Firefox is out of step here. However if you are not
modifying the hidden inputs in the current page prior to posting, that
shouldn't be problem.

If you are using script to put values from the search string into the
form, you are in trouble as IE will clear the hidden inputs if reset is
clicked. You'll need to get the URL and store it, then have your own
reset button that resets visible controls but not hidden ones.

[...]

--
Rob
Nov 24 '05 #4
On 2005-11-24, Ed Jay <ed***@aes-intl.com> wrote:

The form is several pages long, with each page loaded from a Perl script.
The form is no larger than what is loaded into the broowser at any one time.
I know of no broweser that interacts directly with perl.
I'm passing variables from page to page by submitting them as hidden input
form elements.


It sounds to me like you are passing variables from form to form

if the hidden elements have been modified (for example by javascript)
then they will be reset to the values the server served them with.

Bye.
Jasen
Nov 25 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3869
by: Matt | last post by:
I want to write a generic clearForm function to clear the form when the user click CLEAR button. Here's my attempts, because I want to take care all html controls. I think I need to test if the...
2
3125
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
3251
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
2
11925
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
24
4465
by: John Gabriel | last post by:
CreateDialogIndirect() fires my Radio button click function without the radio button having being clicked. I am using VC++ 2003.NET. I believe this is yet another Microsoft bug. Have checked dialog...
2
5877
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
2506
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
5
3587
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at:...
53
8315
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.