
Originally Posted by
jscheuer1
To gain control over all checkboxes of a given name however, use:
var boxes=document.getElementsByTagName('input')
for (var i = 0; i < boxes.length; i++){
if (boxes[i].name=='v42')
do something here
}
That would iterate over all input elements in the document with the name, v42. For checkboxes only,
Code:
var group;
if(document.getElementsByName) {
group = document.getElementsByName('V42');
for(var i = 0, n = group.length; i < n; ++i) {
if('checkbox' == group[i].type) {
/* Act here */
}
}
}
If we're just talking about checkboxes within a particular form, and we probably are, then:
Code:
var group = document.forms.formName.elements.V42;
for(var i = 0, n = group.length; i < n; ++i) {
if('checkbox' == group[i].type) {
/* Act here */
}
}

Originally Posted by
bluemonster7754
Would the script look like:
<input type=checkbox value="1" id="V42_1" name="V42 onClick("document.getElementById("V42_2").checked")>?
No. It would need to be much more complicated, which is why you should go back to radio buttons - they do the work for you. If you're worried about clarity, then obviously you need to reorganise the layout. This could be achieved by placing each question on a single line/row (a very sensible thing to do), or use fieldset elements to group questions.
Using a script is not a solution, particularly as scripts can be circumvented or disabled.
Mike
Bookmarks