how to uncheck a radiobutton

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aswath
    New Member
    • Mar 2008
    • 18

    how to uncheck a radiobutton

    hi all..
    i have a small doubt.. i have two radiobutton on my page.. both unchecked initally.. on clicking either of the radiobutton few apporiate html contols ll appear.. after submitting the form and clicking the back button of my browser one radiobutton is in the clicked mode but its respective contoles are not appearing..

    can anyone guide me with an answer.. thanks in advance..

    i used //document.g.gg.c hecked = false;
    its aint working..

    Aswath.N.S
    (knowledge is power)
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    please post the code you already have. you could call a function onload of the page that inits the state of the buttons ... but i think it would be better to see what you have so far at first ...

    kind regards

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      Originally posted by aswath
      hi all..
      i have a small doubt.. i have two radiobutton on my page.. both unchecked initally.. on clicking either of the radiobutton few apporiate html contols ll appear.. after submitting the form and clicking the back button of my browser one radiobutton is in the clicked mode but its respective contoles are not appearing..

      can anyone guide me with an answer.. thanks in advance..

      i used //document.g.gg.c hecked = false;
      its aint working..

      Aswath.N.S
      (knowledge is power)

      Hello Aswanth, I hope this code may be helpful for you. if more doubt pls post back your code

      [HTML]<html>
      <head>
      <script type="text/javascript">
      function doThis()
      {
      var x = document.getEle mentById('opt1' ).value;
      if(x==1)
      document.getEle mentById('opt2' ).value=0;
      else
      document.getEle mentById('opt1' ).value=1;
      }
      </script>
      </head>
      <body>
      <input type="radio" name="rad" id="opt1" onclick="doThis ()">Select1<b r/>
      <input type="radio" name="rad" id="opt2" onclick="doThis ()">Select2
      </body>
      </html>[/HTML]

      Regards
      Ramanan Kalirajan

      Comment

      • aswath
        New Member
        • Mar 2008
        • 18

        #4
        hi frnds..
        thanks for ur attempts.
        i tried init the form on load of the form.. aint working....
        below is the code that i used..

        [HTML] <script language="javas cript">
        function call(){

        if(document.g.m odi_id.checked= =true){
        // alert(document. g.category1.val ue);
        document.getEle mentById('modif y_txt').style.d isplay= 'block';
        document.getEle mentById('add_n ew_txt').style. display= 'none';

        }
        if(document.g.a dd_id.checked== true){
        // alert(document. g.category2.val ue);
        document.getEle mentById('add_n ew_txt').style. display= 'block';
        document.getEle mentById('modif y_txt').style.d isplay= 'none';
        }

        }
        </script>
        </head>
        <body>
        <form name="g" action="index.j sp">

        modify<input type="radio" name="category" id="modi_id" value="modify" onclick="call() ;"/>
        add new<input type="radio" name="category" id="add_id" value="add_new" onclick="call() ;"/>
        <input type="text" class="text" id="modify_txt " value="modify" />
        <input type="text" class="text" id="add_new_txt " value="add" />
        <input type="submit" value="submit" />

        </form>[/HTML]

        now all i want to do is, on submitting the form and comming back to the same page i want those radiobuttons to be unchecked(some kind of page refrersh ll help i think, however am unable to do it)..
        thanks frnds...
        Last edited by gits; Mar 24 '08, 02:17 PM. Reason: added code tags

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          as i said you just have to call a init-function on page load ... have a look at the example:

          [CODE=javascript]function init_radios() {
          var r = document.getEle mentsByTagName( 'input');

          for (var i = 0, n; n = r[i]; i++) {
          if (n.type == 'radio') {
          n.checked = false;
          }
          }
          }
          [/CODE]
          now call that in the onload:

          [HTML]<body onload="init_ra dios();">
          [/HTML]
          that function unchecks all radio-buttons on your page

          kind regards

          Comment

          • aswath
            New Member
            • Mar 2008
            • 18

            #6
            thanks a lot pal.. its working..

            regards,
            aswath.n.s
            (knowledge is power)

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              :) ... no problem ... post back to the forum anytime you have more questions ...

              kind regards

              Comment

              Working...