473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.substring(9);
if (OpenOnly == "True") {
document.ViewOptions.Open.checked = true;
}
else {
document.ViewOptions.All.checked = true;
}
}

<body onload="setRadioForm()">
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='ViewOptions">
<input type="radio" name="Open" value="True"
onclick="setCookie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCookie("False")>Always 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 16263
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.ViewOptions.Open[0].checked 2nd
radio button: document.ViewOptions.Open[1].checked

John

"Ken Loomis" <kl*****@notarealaddress.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.substring(9);
if (OpenOnly == "True") {
document.ViewOptions.Open.checked = true;
}
else {
document.ViewOptions.All.checked = true;
}
}

<body onload="setRadioForm()">
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='ViewOptions">
<input type="radio" name="Open" value="True"
onclick="setCookie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCookie("False")>Always 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*****@notarealaddress.com> wrote:
Hello:

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

onclick="setCookie('True')">

....and make sure that quotes are paired.
<input type="radio" name="All" value="False"
onclick=setCookie("False")>Always 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="ViewOptions">
<INPUT type="radio" name="items" value="open"
onclick="setCookie('True')"> Always, show me open items only.
<INPUT type="radio" name="items" value="all"
onclick="setCookie('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.******@blueyonder.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********@link.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.ViewOptions.Open[0].checked 2nd
radio button: document.ViewOptions.Open[1].checked

John

"Ken Loomis" <kl*****@notarealaddress.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.substring(9);
if (OpenOnly == "True") {
document.ViewOptions.Open.checked = true;
}
else {
document.ViewOptions.All.checked = true;
}
}

<body onload="setRadioForm()">
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='ViewOptions">
<input type="radio" name="Open" value="True"
onclick="setCookie("True")> Always, show me open items only.
<input type="radio" name="All" value="False"
onclick=setCookie("False")>Always 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.******@blueyonder.co.invalid> wrote:
On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
<kl*****@notarealaddress.com> wrote:
Hello:

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


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="ViewOptions">
<INPUT type="radio" name="items" value="open"
onclick="setCookie('True')"> Always, show me open items only.
<INPUT type="radio" name="items" value="all"
onclick="setCookie('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.******@blueyonder.co.invalid> wrote:
On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
<kl*****@notarealaddress.com> wrote:
Hello:

<form name='ViewOptions">


Make sure the quotes match: name="ViewOptions" or name='ViewOptions'


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
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 ......
0
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...
4
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...
4
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...
10
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...
2
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...
5
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...
2
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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
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...
0
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,...
0
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...

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.