Checked radio button doesn't uncheck

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Loomis

    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





  • johkar

    #2
    Re: Checked radio button doesn't uncheck

    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" <kloomis@notare aladdress.com> wrote in message
    news:j064vv4h6r puq1r4l74t7dtgt 041atgolh@4ax.c om...[color=blue]
    > 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
    >
    >
    >
    >
    >[/color]


    Comment

    • Michael Winter

      #3
      Re: Checked radio button doesn't uncheck

      On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
      <kloomis@notare aladdress.com> wrote:
      [color=blue]
      > Hello:
      >
      > <form name='ViewOptio ns">[/color]

      Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'
      [color=blue]
      > <input type="radio" name="Open" value="True"
      > onclick="setCoo kie("True")> Always, show me open items only.[/color]

      Use a different quote character when nesting:

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

      ....and make sure that quotes are paired.
      [color=blue]
      > <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?[/color]

      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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Ken Loomis

        #4
        Re: Checked radio button doesn't uncheck

        John:

        Thank you. Perfect!

        Ken


        On Wed, 31 Dec 2003 01:10:36 GMT, "johkar" <nosendjunk@lin k.net>
        wrote:
        [color=blue]
        >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" <kloomis@notare aladdress.com> wrote in message
        >news:j064vv4h6 rpuq1r4l74t7dtg t041atgolh@4ax. com...[color=green]
        >> 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
        >>
        >>
        >>
        >>
        >>[/color]
        >[/color]

        Comment

        • Ken Loomis

          #5
          Re: Checked radio button doesn't uncheck

          On Wed, 31 Dec 2003 01:33:00 GMT, Michael Winter
          <M.Winter@bluey onder.co.invali d> wrote:
          [color=blue]
          >On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
          ><kloomis@notar ealaddress.com> wrote:
          >[color=green]
          >> Hello:
          >>
          >> <form name='ViewOptio ns">[/color]
          >
          >Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'[/color]

          Michael, Thank you. The quoting in my code was correct. I transcribed
          it wrong in the message.
          [color=blue]
          >
          >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>
          >[/color]

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

          Right, Thanks.

          Ken



          Comment

          • Lee

            #6
            Re: Checked radio button doesn't uncheck

            Ken Loomis said:[color=blue]
            >
            >On Wed, 31 Dec 2003 01:33:00 GMT, Michael Winter
            ><M.Winter@blue yonder.co.inval id> wrote:
            >[color=green]
            >>On Tue, 30 Dec 2003 19:48:01 -0500, Ken Loomis
            >><kloomis@nota realaddress.com > wrote:
            >>[color=darkred]
            >>> Hello:
            >>>
            >>> <form name='ViewOptio ns">[/color]
            >>
            >>Make sure the quotes match: name="ViewOptio ns" or name='ViewOptio ns'[/color]
            >
            >Michael, Thank you. The quoting in my code was correct. I transcribed
            >it wrong in the message.[/color]

            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.

            Comment

            • Ken Loomis

              #7
              Re: Checked radio button doesn't uncheck

              On 31 Dec 2003 00:03:25 -0800, Lee <REM0VElbspamtr ap@cox.net> wrote:
              [color=blue][color=green]
              >>Michael, Thank you. The quoting in my code was correct. I transcribed
              >>it wrong in the message.[/color]
              >
              >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.[/color]

              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

              Comment

              Working...