Script avec name checkbox avec crochets []
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:
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> |