Checked radio button doesn't uncheck

K

Ken Loomis

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?
 
K

Ken Loomis

John:

Thank you. Perfect!

Ken


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 said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top