Bonjour, voici un script qui marche et qui coche toutes mes checkbox quand je sélectionne "Administrator" dans mon menu déroulant et les décoche si je sélectionne quelque chose d'autre.
Le problème est que j'ai besoin que ma partie name="genre" de mes checkbox soit name="genre[]" car je les traitent ensuite pour les insérer dans une base de données.
Quand name="genre[]" mon script javascript ne marche plus car il n'a pas l'air d'aimer les crochets.
Quelle solution il y a t-il ?
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 <html> <head> <script type="text/javascript"> function allchecked(form) { var max = form.groupe.length+1; for (i=1; i<max; i++) { document.getElementById(i).checked = "checked"; } } function nonechecked(form) { var max = form.groupe.length+1; for (i=1; i<max; i++) { document.getElementById(i).checked = ""; } } </script> </head> <body> <form> <select class = "bigroll" id="mabox" type="text" name="status"> <option onclick="nonechecked(this.form)"></option> <option value="1" onclick="allchecked(this.form)">Administrator</option> <option value="2" onclick="nonechecked(this.form)">Leader</option> <option value="3" onclick="nonechecked(this.form)">Member</option> </select> <input type="checkbox" id="1" name="groupe" value="9"/>group9<br/> <input type="checkbox" id="2" name="groupe" value="12"/>group12<br/> <input type="checkbox" id="3" name="groupe" value="13"/>group13<br/> <input type="checkbox" id="4" name="groupe" value="3"/>group3<br/> <input type="checkbox" id="5" name="groupe" value="4"/>group4<br/> </form> </body> </html>
Partager