I have a simple form which includes lots of radio buttons. Some of them are selected, some of the are not. Is there a way to get them all and set them to not checked. I guess setting to not checked can be done like this:
button.checked = false;
Question is, how do I get all the buttons?
Thanks!
Your question is tagged both javascript and prototypejs. If you want more syntactic sugar from PrototypeJS, then answer may look like
$$('input[type="radio"]:checked').invoke('setValue', false);
translation from Prototype
to english sounds like invoke setValue(false) operation on all checked radio buttons
.
To search in one form you can use somewhat similar construction
$('yourFormId').select('input[type="radio"]:checked').invoke('setValue', false);
If you want plain old IE6-compatible JavaScript, then answer will be
var inputs = document.getElementsByTagName('input');
for (var i = 0, len = inputs.length; i < len; ++i) {
if (inputs[i].type === "radio") {
inputs[i].checked = false;
}
}
$$('input[type="radio"]:checked').each(function(c){
$(c).checked = false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With