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 42 43 44 45 46 47 48 49
| <html>
<head>
...
<script type="text/javascript">
<!--
// ==========================
// Script réalisé par Eric Marcus - Aout 2006
// ==========================
// conteneur = id du bloc (<div>, <p> ...) contenant les checkbox
// a_faire = '0' pour tout décocher
// a_faire = '1' pour tout cocher
// a_faire = '2' pour inverser la sélection
function GereChkbox(conteneur, a_faire) {
var blnEtat=null;
var Chckbox = document.getElementById(conteneur).firstChild;
while (Chckbox!=null) {
if (Chckbox.nodeName=="INPUT")
if (Chckbox.getAttribute("type")=="checkbox") {
blnEtat = (a_faire=='0') ? false : (a_faire=='1') ? true : (document.getElementById(Chckbox.getAttribute("id")).checked) ? false : true;
document.getElementById(Chckbox.getAttribute("id")).checked=blnEtat;
}
Chckbox = Chckbox.nextSibling;
}
}
//-->
</script>
...
</head>
<body>
<form>
<input type="button" value="Tout cocher" onClick="GereChkbox('div_chck','1');">
<input type="button" value="Tout décocher" onClick="GereChkbox('div_chck','0');">
<input type="button" value="Inverser la sélection" onClick="GereChkbox('div_chck','2');">
<br /><br />
<div id="div_chck">
<input type="checkbox" name="checkbox1" id="checkbox1" value="1"><label for="checkbox1">Choix 1</label><br />
<input type="checkbox" name="checkbox2" id="checkbox2" value="2"><label for="checkbox2">Choix 2</label><br />
<input type="checkbox" name="checkbox3" id="checkbox3" value="3"><label for="checkbox3">Choix 3</label><br />
<input type="checkbox" name="checkbox4" id="checkbox4" value="4"><label for="checkbox4">Choix 4</label><br />
<input type="checkbox" name="checkbox5" id="checkbox5" value="5"><label for="checkbox5">Choix 5</label>
</div>
</form>
</body>
</html> |
Partager