1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <!DOCTYPE html>
<html>
<head>
<script>
//<!--
function checkBoxes() {
var nbCheckBoxes = 2;
var allInputs = document.getElementsByTagName('input');
for (i = 0; i < allInputs.length && i < nbCheckBoxes; i++) {
if (allInputs[i].type == 'checkbox') {
allInputs[i].checked = true;
}
}
}
window.onload = function() {
document.getElementById("checkButton").addEventListener("click", checkBoxes, false);
};
//-->
</script>
</head>
<body>
<form id="myForm" name="myForm">
<button type="button" id="checkButton">Cocher les 2 premières cases</button>
<input type="checkbox" value="value1" />
<input type="checkbox" value="value2" />
<input type="checkbox" value="value3" />
<input type="checkbox" value="value4" />
<input type="checkbox" value="value5" />
</form>
</body>
</html> |
Partager