Controler des checkbox
Fermé
Catherine
-
3 nov. 2005 à 14:27
mgwilow Messages postés 2 Date d'inscription lundi 19 janvier 2015 Statut Membre Dernière intervention 19 janvier 2015 - 19 janv. 2015 à 19:48
mgwilow Messages postés 2 Date d'inscription lundi 19 janvier 2015 Statut Membre Dernière intervention 19 janvier 2015 - 19 janv. 2015 à 19:48
A voir également:
- Controler des checkbox
- Sandra a décidé de mieux contrôler son image et sa présence sur différents réseaux sociaux. qu’est-il possible de faire sur ces réseaux ? - Forum Études / Formation High-Tech
- Vba checkbox value ✓ - Forum Excel
- Checkbox onchange ✓ - Forum Webmastering
- Contrôler barre de son avec télécommande bell - Forum Télécommande
- Fan controler - Télécharger - Informations & Diagnostic
4 réponses
HackTrack
Messages postés
618
Date d'inscription
vendredi 26 juillet 2002
Statut
Membre
Dernière intervention
13 juillet 2013
972
3 nov. 2005 à 15:10
3 nov. 2005 à 15:10
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function checkSelect(elmId){
maxOptionsSelect = 7;
form = document.all("detailform");
inputs = form.getElementsByTagName("input");
count = 0;
for(i=0 ; i<inputs.length ; i++){
if(inputs[i].type=="checkbox" && inputs[i].checked==true){
count++;
}
}
if(count > maxOptionsSelect){
document.all(elmId).checked=false;
alert("Vous ne pouvez sélectionner que maximum " + maxOptionsSelect + " options");
return false;
}
return false;
}
</script>
</head>
<body>
<form name="detailform">
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_1"/>a<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_2"/>b<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_3"/>c<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_4"/>d<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_5"/>e<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_6"/>f<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_7"/>g<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_8"/>h<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_9"/>i<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_10"/>j<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_11"/>k<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_12"/>l<br/>
<input type="checkbox" onclick="javascript:checkSelect(this.id);" id="cb_13"/>m<br/>
</form>
</body>
</html>
;-)
HackTrack
wiwimagique
Messages postés
481
Date d'inscription
mardi 21 janvier 2003
Statut
Membre
Dernière intervention
20 avril 2006
108
3 nov. 2005 à 14:33
3 nov. 2005 à 14:33
il faut faire ça en javascript
à chaque fois q'un utilisateur coche ou décoche un checkbox ( onclick ) tu appelles une fonction
la fonction va parcourir la totalité des checkbox et compter combien sont cochés (.checked = true)
si ça dépasse 6, tu fais ton alert('message d erreur') et tu décoches la box qui vient d'etre modifiée.
à chaque fois q'un utilisateur coche ou décoche un checkbox ( onclick ) tu appelles une fonction
la fonction va parcourir la totalité des checkbox et compter combien sont cochés (.checked = true)
si ça dépasse 6, tu fais ton alert('message d erreur') et tu décoches la box qui vient d'etre modifiée.
Pour dire ça autant se taire...
Lool t'as vu ton message la ! :D
S.V.I.N.K.E.L.S
-->on se gave d'orge d'houblon et de malt a wishy: C real killer
Lool t'as vu ton message la ! :D
S.V.I.N.K.E.L.S
-->on se gave d'orge d'houblon et de malt a wishy: C real killer
mgwilow
Messages postés
2
Date d'inscription
lundi 19 janvier 2015
Statut
Membre
Dernière intervention
19 janvier 2015
1
19 janv. 2015 à 19:48
19 janv. 2015 à 19:48
bonjour, je n'y connais pas grand chose en javascript mais comment faire pour ne plus permettre de cocher d'autre case après le nombre de 6 dans l'exemple?
le code fonctionne nickel merci bcp.
le code fonctionne nickel merci bcp.
3 nov. 2005 à 15:12
Un grand merci pour le code, je le tiens bien au chaud pour le tester
Merci mille fois ;o))
Catherine
3 nov. 2005 à 15:16
C'est parce que je suis flemmard :-D
3 nov. 2005 à 15:25
;-)
HackTrack
3 nov. 2005 à 15:35
Je viens de le tester sur mon form, super génial ;o))
Merci encore de ton aide
3 nov. 2005 à 20:40
A ton service...
;-)
HackTrack