Javascript Help - accessing radio buttons

Damn if I can get this.

I have a function in javascript that accepts a string containing the radio button group name, a boolean (the intended checked property value of the radio button) and an integer that points to the button in the group.



function ChangeHTML(id, val, radio) 
{		
	
//		var HTMLElement = document.getElementById(id[radio]);
//             HTMLElement.checked = val;

//		var HTMLElement = document.getElementByTagName(id);
//		HTMLElement[radio].checked = val;

//		var HTMLElement = document.getElementByTagName(id);
//		HTMLElement[radio].checked = val;

}


I’ve tried the above three statements and none of them seem to work.

The following works fine with checkboxes btw:



                var HTMLElement = document.getElementById(id);
		HTMLElement.checked = val;


Anyone care to help me out?

Well see, a radio group is a group of radios, so it can’t be checked or not. A single radio can be checked, tho.

So you have to loop through each item in the group and if one of them is checked, then you can say that the group is checked.

Such as



for (i=myradiobuttonname.length-1; i > -1; i--) {
if (myradiobuttonname*.checked) {
myvalueiwanttoget = myradiobuttonname*.value;
}


I don’t know if that syntax is exactly right, but hopefully it put you down the right path…