Select all radio buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ashvini Shanbhag
    New Member
    • Jun 2007
    • 5

    Select all radio buttons

    Hi,

    i m new in javascript. i have the below problem. Plz help.

    There are two main radio buttons and list of radio button under each one . On selecting of the first radio button a list of radio buttons under it must be selected . And on selecting the other radio button the list of radio buttons must be cleared under the first one and the list under the second must be selected.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Show some code, e.g. at least your HTML.

    You can't select all radio buttons, only one, unless that's not what you meant.

    Comment

    • Ashvini Shanbhag
      New Member
      • Jun 2007
      • 5

      #3
      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitl ed Document</title>
      </head>

      <body>
      <form name="frm" style="display: inline ">
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="Calendar Content" id="user1_platf orm1" style="display: inline">
      <tr>
      <td align="center" nowrap class="tblHeade r">Approve deactivation
      <table border="0" cellpadding="0" cellspacing="2" >
      <tr>
      <td><input name="rdoApp1" type="radio" class="RADIO" value="radiobut ton" onClick="aprvAl l(3, this.name)"></td>
      <td class="contentT ext">Approve All </td>
      <td><input name="rdoApp1" type="radio" class="RADIO" value="radiobut ton" onClick="aprvAl l(3, this.name)"></td>
      <td class="contentT ext">Reject All </td>
      </tr>
      </table></td>
      </tr>
      <tr class="tableCel lOff">
      <td align="center" class="TableTex t"><input name="rdoApp1_1 " type="radio" class="RADIO" value="yes">
      Yes
      <input name="rdoApp1_1 " type="radio" class="RADIO" value="radiobut ton">
      No </td>
      </tr>
      <tr class="tableCel lOff2">
      <td align="center" class="TableTex t"><input name="rdoApp1_2 " type="radio" class="RADIO" value="radiobut ton">
      Yes
      <input name="rdoApp1_2 " type="radio" class="RADIO" value="radiobut ton">
      No </td>
      </tr>
      <tr class="tableCel lOff2">
      <td align="center" class="TableTex t"><input name="rdoApp1_3 " type="radio" class="RADIO" value="radiobut ton">
      Yes
      <input name="rdoApp1_3 " type="radio" class="RADIO" value="radiobut ton">
      No </td>
      </tr>
      </table>
      </form>
      </body>
      </html>[/HTML]
      Please post code using code tags - MODERATOR
      Last edited by acoder; Jun 28 '07, 10:34 AM. Reason: Code in tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Oh, I see now what you mean.

        Use the checked property. To access the radio button, either use the form elements array or use document.getEle mentById after giving your radio buttons ids.

        Comment

        • KishoreM
          New Member
          • Jun 2007
          • 12

          #5
          Originally posted by Ashvini Shanbhag
          Hi,

          i m new in javascript. i have the below problem. Plz help.

          There are two main radio buttons and list of radio button under each one . On selecting of the first radio button a list of radio buttons under it must be selected . And on selecting the other radio button the list of radio buttons must be cleared under the first one and the list under the second must be selected.
          Hi,

          Here I have written a sample code hop it will be useful for you if you have any more probs plez revert to me.

          regards,

          Kishore M
          [HTML]
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>Untitl ed Document</title>
          <script>

          function doAll(count,sho wObj,hideObjNam e)
          {
          if(showObj.chec ked == true)
          {
          document.getEle mentById(hideOb jName).checked= false;

          for(i=1;i <=count;i++)
          {
          document.getEle mentById(showOb j.name+"_"+i).c hecked=true;
          document.getEle mentById(hideOb jName+"_"+i).ch ecked=false;

          }
          }

          }


          </script>
          </head>

          <body>
          <form name="frm" style="display: inline ">
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="Calendar Content" id="user1_platf orm1" style="display: inline">
          <tr>
          <td align="center" nowrap class="tblHeade r">Approve deactivation
          <table border="0" cellpadding="0" cellspacing="2" >
          <tr>
          <td><input name="rdoApp1" type="radio" value="radiobut ton" class="RADIO" onClick="doAll( 3,this,'rdoRej1 ')"></td>
          <td class="contentT ext">Approve All </td>
          <td><input name="rdoRej1" type="radio" value="radiobut ton" class="RADIO" onClick="doAll( 3,this,'rdoApp1 ')"></td>
          <td class="contentT ext">Reject All </td>
          </tr>
          </table></td>
          </tr>
          <tr class="tableCel lOff">
          <td align="center" class="TableTex t"><input name="rdoApp1_1 " id=="rdoApp1_1" type="radio" class="RADIO" value="radiobut ton">
          Yes
          <input name="rdoRej1_1 " id=="rdoRej1_1" type="radio" class="RADIO" value="radiobut ton">
          No </td>
          </tr>
          <tr class="tableCel lOff2">
          <td align="center" class="TableTex t"><input name="rdoApp1_2 " id=="rdoApp1_2" type="radio" class="RADIO" value="radiobut ton">
          Yes
          <input name="rdoRej1_2 " id=="rdoRej1_2" type="radio" class="RADIO" value="radiobut ton">
          No </td>
          </tr>
          <tr class="tableCel lOff2">
          <td align="center" class="TableTex t"><input name="rdoApp1_3 " id=="rdoApp1_3" type="radio" class="RADIO" value="radiobut ton">
          Yes
          <input name="rdoRej1_3 " id=="rdoRej1_3" type="radio" class="RADIO" value="radiobut ton">
          No </td>
          </tr>
          </table>
          </form>
          </body>
          </html>

          [/HTML]

          Comment

          • Ashvini Shanbhag
            New Member
            • Jun 2007
            • 5

            #6
            thanx acoder and kishore....
            the code works properly.
            thank u very much.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by KishoreM
              Hi,

              Here I have written a sample code hop it will be useful for you if you have any more probs plez revert to me.

              regards,

              Kishore M
              For some reason, you have id== instead of id= for all the radio buttons.

              Comment

              • Ashvini Shanbhag
                New Member
                • Jun 2007
                • 5

                #8
                there's one prblm... when we selected "yes" or "no" radio button individualy, then only one of the two should be selected.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  That's because they should have the same name to be radio buttons. Change the names of the 'No' radio buttons back to how you had it before.

                  Comment

                  • Ashvini Shanbhag
                    New Member
                    • Jun 2007
                    • 5

                    #10
                    i added a new function to the individual "yes" and "no" buttons. now it's working.
                    and by changing the id names,,it won't work.
                    But can't we add in the same function.

                    Comment

                    • KishoreM
                      New Member
                      • Jun 2007
                      • 12

                      #11
                      Originally posted by acoder
                      For some reason, you have id== instead of id= for all the radio buttons.
                      Sorry,

                      It was by mistake not intentionally.. ......

                      Comment

                      • KishoreM
                        New Member
                        • Jun 2007
                        • 12

                        #12
                        Originally posted by Ashvini Shanbhag
                        i added a new function to the individual "yes" and "no" buttons. now it's working.
                        and by changing the id names,,it won't work.
                        But can't we add in the same function.
                        Hi,
                        Please change the names of radio to resolve this probs but don't change the
                        id because javascript code is using id.here is updated code........

                        [HTML]
                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                        <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                        <title>Untitl ed Document</title>
                        <script>
                        function doAll(count,sho wObj,hideObjNam e)
                        {
                        if(showObj.chec ked == true)
                        {
                        document.getEle mentById(hideOb jName).checked= false ;
                        for(i=1;i <=count;i++)
                        {
                        document.getEle mentById(showOb j.name+"_"+i).c hecked=true;
                        document.getEle mentById(hideOb jName+"_"+i).ch ecked=false;
                        }
                        }
                        }
                        </script>
                        </head>
                        <body>
                        <form name="frm" style="display: inline ">
                        <table width="100%" border="0" cellpadding="0" cellspacing="1" class="Calendar Content" id="user1_platf orm1" style="display: inline">
                        <tr>
                        <td align="center" nowrap class="tblHeade r">Approve deactivation
                        <table border="0" cellpadding="0" cellspacing="2" >
                        <tr>
                        <td><input name="rdoApp1" type="radio" value="radiobut ton" class="RADIO" onClick="doAll( 3,this,'rdoRej1 ')"></td>
                        <td class="contentT ext">Approve All </td>
                        <td><input name="rdoRej1" type="radio" value="radiobut ton" class="RADIO" onClick="doAll( 3,this,'rdoApp1 ')"></td>
                        <td class="contentT ext">Reject All </td>
                        </tr>
                        </table></td>
                        </tr>
                        <tr class="tableCel lOff">
                        <td align="center" class="TableTex t"><input name="rdoApp1_1 " id="rdoApp1_1" type="radio" group="test" class="RADIO" value="radiobut ton">
                        Yes
                        <input name="rdoApp1_1 " id="rdoRej1_1" type="radio" class="RADIO" group="test" value="radiobut ton">
                        No </td>
                        </tr>
                        <tr class="tableCel lOff2">
                        <td align="center" class="TableTex t"><input name="rdoApp1_2 " id="rdoApp1_2" type="radio" class="RADIO" value="radiobut ton">
                        Yes
                        <input name="rdoApp1_2 " id="rdoRej1_2" type="radio" class="RADIO" value="radiobut ton">
                        No </td>
                        </tr>
                        <tr class="tableCel lOff2">
                        <td align="center" class="TableTex t"><input name="rdoApp1_3 " id="rdoApp1_3" type="radio" class="RADIO" value="radiobut ton">
                        Yes
                        <input name="rdoApp1_3 " id="rdoRej1_3" type="radio" class="RADIO" value="radiobut ton">
                        No </td>
                        </tr>
                        </table>
                        </form>
                        </body>
                        </html>

                        [/HTML]

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by KishoreM
                          Sorry,

                          It was by mistake not intentionally.. ......
                          That's ok. I was just pointing it out in case someone tried to use the code.

                          Comment

                          Working...