I’m working on a .NET-powered questionnaire which contains several repeater controls, each row of which contains three radiobuttons. I’m trying to write a simple Javascript function to check all the controls on the page which contain the word ‘chkGreen’ in the control name/id.
The page looks something like this:
Repeater 1 Description 1 ( ) Green ( ) Yellow ( ) Red Description 2 ( ) Green ( ) Yellow ( ) Red Description 3 ( ) Green ( ) Yellow ( ) Red Repeater 2 Description 1 ( ) Green ( ) Yellow ( ) Red Description 2 ( ) Green ( ) Yellow ( ) Red Description 3 ( ) Green ( ) Yellow ( ) Red
Here’s the function so far:
for (i = 0; i < document.Form1.elements.length; i++) { var _control = document.Form1.elements[i].id if (_control.indexOf('chkGreen') > 0) { eval(_control.checked = true); } }
This function does not work. When I add a document.write or alert() to the statement, it properly fires, so the logic is apparently working, it’s just the actual radiobutton check code is not working.
Any thoughts?
You don’t need to eval the _control.checked line.