I’ve got the following HTML which has been looped around in smarty template language:
<td><input type="checkbox" name="confirmRelated[{$relatedIP.ipInt}_{$relatedIP.patternID}][confirm]" /></td>
<td><input type="hidden" name="confirmRelated[{$relatedIP.ipInt}_{$relatedIP.patternID}][ipInt]" value="{$relatedIP.ipInt}">{$relatedIP.robotIP}</td>
<td><input type="hidden" name="confirmRelated[{$relatedIP.ipInt}_{$relatedIP.patternID}][patternID]" value="{$relatedIP.patternID}">{$relatedIP.pattern}</td>
I’m trying to access the fields in javascript, but I’m having troubles with even the basics so far. Can anyone help?
var boxes = document.getElementsByName('confirmRelated');
alert(boxes.length);
That returns 0 at the moment, which is obviously wrong. I’m attempting to loop through all of them and check the checkbox “confirm” ones.
Any help appreciated.
You can’t access them via
document.getElementByName(). The following should work:That would check all inputs with the type checkbox.
EDIT: Using a framework like prototype you can make it a lot easier: