For example I have html elements like
<input type="radio" name="disableme" id=1> Animal
<input type="radio" name="disableme" id=2> Mammal
<input type="radio" name="disableme" id=3> Human
I tried like , document.formName.disableme.disabled = true;
But it didn't worked..
I can do it using Id. But I need it in one shot.
Please help.
Try this code
var radio=document.getElementsByName("disableme");
var len=radio.length;
for(var i=0;i<len;i++)
{
radio[i].disabled=true;
}
<input type="radio" name="disableme" id=1> Animal
<input type="radio" name="disableme" id=2> Mammal
<input type="radio" name="disableme" disabled="disabled" id=3> Human
I tried like , document.formName.disableme.disabled = true; But it didn't worked..
Because if you have more than one form control with the same name, you will get back an HTML Form Controls Collection. So loop over the collection:
var radios = document.formName.disableme;
for (var i=0, iLen=radios.length; i<iLen; i++) {
radios[i].disabled = true;
}
There is no need to add an ID.
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