グループチェックall


<html>
<head>
</head>
<body>
	<form name=myform>
<div>
<span><input type="checkbox" name="recname" value="2">a1</span>
<span><input type="checkbox" name="recname" value="2">a2</span>
<span><input type="checkbox" name="recname" value="2">a3</span>
<span><input type="checkbox" class="aaaa" name="2" value="a_all" id="a" onclick="CheckAll(this.form,this.name,this.checked)">a_all</span><br><br>

<span><input type="checkbox" name="recname" value="12">b1</span>
<span><input type="checkbox" name="recname" value="12">b2</span>
<span><input type="checkbox" name="recname" value="12">b3</span>
<span><input type="checkbox" name="12" value="b_all" id="b" onclick="CheckAll(this.form,this.name,this.checked)">b_all</span><br><br>

<span><input type="checkbox" name="recname" value="112">c1</span>
<span><input type="checkbox" name="recname" value="112">c2</span>
<span><input type="checkbox" name="recname" value="112">c3</span>
<span><input type="checkbox" name="112" value="c_all" id="c" onclick="CheckAll(this.form,this.name,this.checked)">c_all</span>
</div>
</form>
<script type="text/javascript">
function getElementsbyClassName(n){
    
    var classElements=[],allElements=document.getElementsByTagName('*');
    
    for(var i=0;i<allElements.length;i++){
            if(allElements[i].className==n){
                    classElements[classElements.length]=allElements[i];
            }
    }
    
    return classElements;
}
		window.ready=load();
		function load(){
			alert("window loaded");
			var temp=getElementsbyClassName('aaaa');
			alert(temp);
			for (var i = 0; i < temp.length; i++) {
				temp[i].parentNode.style.backgroundColor='SkyBlue';
			};
		}
		function CheckAll(obj,thename,ischecked){
			for (var i = 0; i < obj.elements.length; i++) {
				var e = obj.elements[i];
				if (e.value==thename) {
					e.checked=ischecked;
				};
			};
		}
	</script>
</body>
</html>