Jump to content
  • 0

How To Uncheck A Radio Button


Darina

Question

3 answers to this question

Recommended Posts

  • 0

The trick is to set the checked property to false. Here's some javascript and jquery that should help (adapted from here):

 

var allRadios = document.getElementsByType('radio');
var booRadio = allRadios[0];
for(var x = 0; x < allRadios.length; x++){
   allRadios[x].onclick = function() {
      if(booRadio == this){
         if(this.checked) this.checked = false;
         booRadio = null;
      } else{
         booRadio = this;
      }
    };
}
Link to comment
Share on other sites

  • 0

I tried the code above and it did not work. This worked for me. Add it to the footer:

<script>
var allRadios = document.getElementById("caspioform").elements;
var booRadio;
var x = 0;
for(x = 0; x < allRadios.length; x++){

        allRadios[x].onclick = function(){

            if(booRadio == this){
                this.checked = false;
        booRadio = null;
            }else{
            booRadio = this;
        }
        };
}
</script>

Link to comment
Share on other sites

  • 0

Hi - here is another way to call a radio button.

<script>

var allRadios = document.querySelectorAll('input[type="radio"]')
var booRadio;
for (var x = 0; x < allRadios.length; x++) {
  
  allRadios[x].onclick= function() {
    
    if (booRadio == this) {
      this.checked = false;
      booRadio = null;
    } else {
      booRadio = this;
    }
  };
}

</script>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...