473,661 Members | 2,494 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 19441
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
3880
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
3136
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
3266
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
11954
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
4528
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
5888
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
2512
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
3592
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
8370
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
8343
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
8856
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...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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
5653
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();...
0
4179
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
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.