473,848 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function to unselect radio buttons

I use window.document .form1.myCheckb ox.checked=fals e;
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 19465
Ed Jay wrote:
I use window.document .form1.myCheckb ox.checked=fals e;
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.ne t.au> wrote:
Ed Jay wrote:
I use window.document .form1.myCheckb ox.checked=fals e;
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
3899
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 control is submit button, regular button. But I don't know what I should do on drop down box? function clearForm() { var i=0;
2
3161
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 they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have two radio buttons to indicate sex (M F). When you have multiple text input boxes with the same...
4
3286
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> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
2
11988
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 them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at run time but with fixed radio buttons (like from an array). I need to create radio buttons based...
24
4576
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 resources and memory - both appear to be in order. Can anyone comment on this? Should CreateDialogIndirect() which is located in dlgcore.cpp ever fire a button click routine??
2
5898
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 the form by changing the visible state of the radio buttons and labels utilising back and next buttons. E.g. Next button makes current radio buttons and labels invisible and
4
2524
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 all twelve. User2 would see buttons 1-3,10-12 and NOT any others, and so on. Since there are several buttons on the page (each one would run a report for them), is there a way to - in an onclick event for each of the buttons - to...
5
3606
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: http://www.geocities.com/usenet_daughter/javascript_radio.htm but for some reason I can only get a value if I hard code the control name.
53
8441
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 language="javascript" type="text/javascript">
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11001
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10722
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7069
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3175
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.