I'm not quite understanding how to loop a large amount of radio buttons to become checked or not. I could probably copy paste some code but I really want to understand this.
So on my document I have a large amount of radio buttons. Such as:
So to select a single button I can do:Code:<table style="width: 100%" Name="Test1"> <tr> <td><a href="#" onclick="test()">Yes</a></td> <td>No</td> <td>DK</td> </tr> <tr> <td><input type="radio" name="Radio1" value="Yes" id="rYes1" /></td> <td><input type="radio" name="Radio1" value="No" id="rNo1"/></td> <td><input type="radio" name="Radio1" value="DK" id="rDK1"/></td> </tr> <tr> <td><input type="radio" name="Radio2" value="Yes" id="rYes2" /></td> <td><input type="radio" name="Radio2" value="No" id="rNo2"/></td> <td><input type="radio" name="Radio2" value="DK" id="rDK2"/></td> </tr> .... </table>
document.testform1.elements.rNo1.checked=true;
It seems like I should be able to create a loop that says:
var i=1;
while (i<=20)
{
document.testform1.elements.rNo[i].checked=true;
i++;
}
This does not work and I'm pretty sure it is because I am not understanding
document.testform1.elements.rNo[i].checked=true;
Normally this would be an array but looking at other code i have no idea what this is saying in javascript.
Any help would be appreciated! Thank You!


Reply With Quote

Bookmarks