bonjour,

j'aimerais modifier cette fonction pour que lorsque tous les choix sont cochés le principal soit coché

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<html><head>
<title>checkbox maître</title>
<script>
//checkbox ou une liste de checkbox.
function selectall(cas,choix){
  //test si on a plusieur ligne
  if(choix.length>0){
    if (cas.checked){
      for (var i=0; i<choix.length;i++){
        choix[i].checked=true
      }
    }
    else{
      for (var i=0; i<choix.length;i++){
        choix[i].checked=false
      }
    }
  }
  else{
    if (cas.checked){
      choix.checked=true
    }
    else{
      choix.checked=false
    }
  }
}
 
function clearcas(cas,choix){
	if (cas.checked){
		cas.checked=false
	}else{
		if (choix.checked){
		cas.checked=true
		}
	}
}
</script>
</head>
 
<body>
<form name="monform">
<input type="checkbox" name="spec" onclick="selectall(document.monform.spec,document.monform.sub_spec)">
puis un liste de checkbox
<input type="checkbox" name="sub_spec" value="1" onclick="clearcas(document.monform.spec,document.monform.sub_spec)">
<input type="checkbox" name="sub_spec" value="2" onclick="clearcas(document.monform.spec,document.monform.sub_spec)">
<input type="checkbox" name="sub_spec" value="3" onclick="clearcas(document.monform.spec,document.monform.sub_spec)"></form>
</body></html>