473,785 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checked radio button doesn't uncheck

Hello:

On a web page I check the value of a cookie and set one of two radio
buttons accordingly.

function setRadioForm() {
var myCookie = document.cookie ;
var OpenOnly = myCookie.substr ing(9);
if (OpenOnly == "True") {
document.ViewOp tions.Open.chec ked = true;
}
else {
document.ViewOp tions.All.check ed = true;
}
}

<body onload="setRadi oForm()">
This works fine. The correct radio button appears checked when the
form opens. However, when the user checks one of the buttons (usually
the unchecked one), both buttons remain checked.

Here's the code on the form:

<form name='ViewOptio ns">
<input type="radio" name="Open" value="True"
onclick="setCoo kie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCook ie("False")>Alw ays show me all items, open and closed.
</form>

The onclick fires correctly, but the button which was not clicked
remains checked. Am I doing something wrong or is this a limitation
in the browser/code?

--
Ken

Jul 20 '05 #1
6 16286
When you have a group of radio buttons (I.E. only one can be selected), you
need to name them the same. The checked value, if any, will be the only one
returned under that name. Since they are named the same you need to access
them like so: 1st radio button: document.ViewOp tions.Open[0].checked 2nd
radio button: document.ViewOp tions.Open[1].checked

John

"Ken Loomis" <kl*****@notare aladdress.com> wrote in message
news:j0******** *************** *********@4ax.c om...
Hello:

On a web page I check the value of a cookie and set one of two radio
buttons accordingly.

function setRadioForm() {
var myCookie = document.cookie ;
var OpenOnly = myCookie.substr ing(9);
if (OpenOnly == "True") {
document.ViewOp tions.Open.chec ked = true;
}
else {
document.ViewOp tions.All.check ed = true;
}
}

<body onload="setRadi oForm()">
This works fine. The correct radio button appears checked when the
form opens. However, when the user checks one of the buttons (usually
the unchecked one), both buttons remain checked.

Here's the code on the form:

<form name='ViewOptio ns">
<input type="radio" name="Open" value="True"
onclick="setCoo kie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCook ie("False")>Alw ays show me all items, open and closed.
</form>

The onclick fires correctly, but the button which was not clicked
remains checked. Am I doing something wrong or is this a limitation
in the browser/code?

--
Ken


Jul 20 '05 #2
On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
<kl*****@notare aladdress.com> wrote:
Hello:

<form name='ViewOptio ns">
Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'
<input type="radio" name="Open" value="True"
onclick="setCoo kie("True")> Always, show me open items only.
Use a different quote character when nesting:

onclick="setCoo kie('True')">

....and make sure that quotes are paired.
<input type="radio" name="All" value="False"
onclick=setCook ie("False")>Alw ays show me all items, open and closed.
</form>

The onclick fires correctly, but the button which was not clicked
remains checked. Am I doing something wrong or is this a limitation
in the browser/code?


Radio buttons must belong to the same 'group' in order to have interaction
with each other. You do this by giving them the same name. Using your code
above, you could do this like so:

<FORM name="ViewOptio ns">
<INPUT type="radio" name="items" value="open"
onclick="setCoo kie('True')"> Always, show me open items only.
<INPUT type="radio" name="items" value="all"
onclick="setCoo kie('False')"> Always show me all items, open and
closed.
</FORM>

With this new arrangement, you might want to rename your cookies (True and
False don't quite make sense in this context).

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
John:

Thank you. Perfect!

Ken
On Wed, 31 Dec 2003 01:10:36 GMT, "johkar" <no********@lin k.net>
wrote:
When you have a group of radio buttons (I.E. only one can be selected), you
need to name them the same. The checked value, if any, will be the only one
returned under that name. Since they are named the same you need to access
them like so: 1st radio button: document.ViewOp tions.Open[0].checked 2nd
radio button: document.ViewOp tions.Open[1].checked

John

"Ken Loomis" <kl*****@notare aladdress.com> wrote in message
news:j0******* *************** **********@4ax. com...
Hello:

On a web page I check the value of a cookie and set one of two radio
buttons accordingly.

function setRadioForm() {
var myCookie = document.cookie ;
var OpenOnly = myCookie.substr ing(9);
if (OpenOnly == "True") {
document.ViewOp tions.Open.chec ked = true;
}
else {
document.ViewOp tions.All.check ed = true;
}
}

<body onload="setRadi oForm()">
This works fine. The correct radio button appears checked when the
form opens. However, when the user checks one of the buttons (usually
the unchecked one), both buttons remain checked.

Here's the code on the form:

<form name='ViewOptio ns">
<input type="radio" name="Open" value="True"
onclick="setCoo kie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCook ie("False")>Alw ays show me all items, open and closed.
</form>

The onclick fires correctly, but the button which was not clicked
remains checked. Am I doing something wrong or is this a limitation
in the browser/code?

--
Ken



Jul 20 '05 #4
On Wed, 31 Dec 2003 01:33:00 GMT, Michael Winter
<M.******@bluey onder.co.invali d> wrote:
On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
<kl*****@notar ealaddress.com> wrote:
Hello:

<form name='ViewOptio ns">
Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'


Michael, Thank you. The quoting in my code was correct. I transcribed
it wrong in the message.

Radio buttons must belong to the same 'group' in order to have interaction
with each other. You do this by giving them the same name. Using your code
above, you could do this like so:

<FORM name="ViewOptio ns">
<INPUT type="radio" name="items" value="open"
onclick="setCoo kie('True')"> Always, show me open items only.
<INPUT type="radio" name="items" value="all"
onclick="setCoo kie('False')"> Always show me all items, open and
closed.
</FORM>

I thought I had to name them differently to reference them. Thanks.
With this new arrangement, you might want to rename your cookies (True and
False don't quite make sense in this context).


Right, Thanks.

Ken

Jul 20 '05 #5
Lee
Ken Loomis said:

On Wed, 31 Dec 2003 01:33:00 GMT, Michael Winter
<M.******@blue yonder.co.inval id> wrote:
On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
<kl*****@nota realaddress.com > wrote:
Hello:

<form name='ViewOptio ns">


Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'


Michael, Thank you. The quoting in my code was correct. I transcribed
it wrong in the message.


So now you've learned why you should *never* transcribe code
into a post when you're asking why it doesn't work. It's
like sending your brother in to the doctor to find out why
your shoulder hurts.

Always copy and paste code that you know shows the problem.

Jul 20 '05 #6
On 31 Dec 2003 00:03:25 -0800, Lee <RE************ **@cox.net> wrote:
Michael, Thank you. The quoting in my code was correct. I transcribed
it wrong in the message.


So now you've learned why you should *never* transcribe code
into a post when you're asking why it doesn't work. It's
like sending your brother in to the doctor to find out why
your shoulder hurts.

Always copy and paste code that you know shows the problem.


Right you are. The code was on a machine not corrected to newsgroups,
and I knew the problem had to be more conceptual than syntactical, but
I take your point.

Ken
Jul 20 '05 #7

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

Similar topics

2
12349
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ... without having to get this value via html, is there any way I can passed the checked value via html .. maybe with syntax like n4.checked.value or something.. Many thanks. <html>
0
1968
by: hy | last post by:
Hi all, I got the question about the radio button. How do i detect previous checked radio button after i checked other's radio button. While the new radio button checked, it need to prompt out a confirm message box, if user click on the 'cancel' button, system will programatically check the previous radio button instead of the latest radio button that checked.
4
10551
by: moondaddy | last post by:
There are different times when I will have a group of checkboxes and need to force only one to be checked at a time. I would also like to do this client side and not require a postback. These checkboxes could be just a group of check boxes across the top of a page, or could be part of a datalist or datagrid. How do I make it so when a use clicks on one checkbox that if another checkbox is checked, it becomes unchecked? Also, is it...
4
11509
by: lemat | last post by:
Hi, I use a radio button form in which users can select a color by clicking on a image. I would like this image to change to another one when it's chosen. (image with a "Chosen" Stamp in the middle) Of course I like it to be restored if hte user select another color. I've tried to add behaviour to the image (swap on click) and on the button (onchange swap restore) but it doesn't work (hte image id swapped and restored almost instantly).
10
18939
by: Bishman | last post by:
Hi, I need to programmatically allow or disallow the selection of multiple checkboxes on a form . At certain times I only want to allow a single selection, at other times I may wish to allow multiple. Is there a way of doing this ? I dont want to use Radio buttons..... Thanks,
2
5893
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
5
4156
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a MySQL database using JavaScript to find a product either by Product ID, Description, or Both. Originally, the 'Both' radio button was "checked" but I now want the 'Product ID' button set as the default choice (as you can see from the code below). ...
2
7318
by: mars123 | last post by:
hi, I am facing a js error in my code, below is the prob. statement I have a radio2 javascript function as below, it works like this.. When a parent radio button is selected only one of its child radio button can be selected and on selection of a new child button(of the same parent) the earlier child button is deselected. When i navigate to this particular page and select a parent and select a child, when i select another child of the...
3
2026
by: tshad | last post by:
I have a form that has 2 sets of radiobuttons. As it happens I created 1 radiobutton and then copied it a pasted it 4 times. I have 4 radiobuttons split up into 2 groupboxes (2 radiobuttons each). When I first start the program none of the radiobuttons are checked. I also have 4 buttons on the bottom of the page. For some reason, when I hit any of the buttons at the bottom of the page,
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10324
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
10147
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
8971
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
7499
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
5380
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...
1
4050
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
2879
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.