Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  81] [ 3]  / answers: 1 / hits: 86925  / 12 Years ago, tue, november 6, 2012, 12:00:00

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.


More From » html

 Answers
21

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.


[#82168] Monday, November 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mathewb

Total Points: 535
Total Questions: 95
Total Answers: 96

Location: British Indian Ocean Territory
Member since Fri, Oct 15, 2021
3 Years ago
;