Clear button radio button

Asked

Viewed 4,336 times

3

Good morning I would like to know how to clean what was clicked on the radio button, because in the textbox I use the name. Clear(); I wonder how I do on the radio button

Thank you.

  • Are these buttons inside a form? Are there more elements you want to clean or just these buttons? In that case it is enough elemento.checked = false;

  • Yes, there are more elements that are being cleaned

  • Have you tried doing form.reset() in the element <form>?

  • It worked out Thank you !!!

2 answers

1

Just change the attribute of the checked for false.

In jQuery, you can select by id or by name, for example:

$('input[name=Choose]').attr('checked',false);

In pure Javascript:

var ele = document.getElementsByName("Choose");
   for(var i=0;i<ele.length;i++)
      ele[i].checked = false;

Taken from Stackoverflow in English in a reply by NVRAM

  • It worked!!! Obr

  • Not at all. Can you mark the answer as you accept, please? Here it is documented in the community.

1

To deselect a specific input just do it elemento.checked = false;.

In case you have several, you have to iterate them and do them one by one. Something like:

var inputs = document.querySelectorAll('input[type="radio"]');
for (var i = 0, l = inputs.length; i < l; i++){
    inputs[i].checked = false;
}

But often what is intended is to re-start a form, this can be done with:

document.querySelector('form').reset();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.