<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
</head>
<body>
<div>
<input type="checkbox" name="a" value="1" />
<input type="checkbox" name="b" value="2" />
<input type="checkbox" name="c" value="3" />
</div>
<script type="text/javascript">
/*<![CDATA[*/
var inputs = document.getElementsByTagName("input"); //or document.forms[0].elements;
var myCheckboxes = []; //will contain all checkboxes
var myCheckboxesChecked = []; //will contain all checked checkboxes
var ci=0;
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
ci++;
myCheckboxes.push(inputs[i]);
inputs[i].onchange="alert('A checkbox value was changed')";
}
}
/*]]>*/
</script>
</body>
</html>
|