Checked radio button doesn't uncheck

Discussion in 'Javascript' started by Ken Loomis, Dec 31, 2003.

  1. Ken Loomis

    Ken Loomis Guest

    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
     
    Ken Loomis, Dec 31, 2003
    #1
    1. Advertising

  2. Ken Loomis

    Ken Loomis Guest

    John:

    Thank you. Perfect!

    Ken


    On Wed, 31 Dec 2003 01:10:36 GMT, "johkar" <>
    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" <> wrote in message
    >news:...
    >> 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
    >>
    >>
    >>
    >>
    >>

    >
     
    Ken Loomis, Dec 31, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    682
  2. pavankumarkavety
    Replies:
    0
    Views:
    1,069
    pavankumarkavety
    May 22, 2008
  3. Hiten
    Replies:
    1
    Views:
    643
    Vidar Petursson
    May 26, 2004
  4. Replies:
    2
    Views:
    158
  5. cerr

    uncheck radio group

    cerr, Nov 5, 2011, in forum: Javascript
    Replies:
    7
    Views:
    1,231
    Dr J R Stockton
    Nov 6, 2011
Loading...

Share This Page