CheckBox decochage automatique
Bonjour, Apres plusieurs recherche et sans réponse à ma question j'ai décidé d'ouvrir une discussion à propos de mon probème.
Je m'explique, Je souhaite que quand ma checkbox "#i0" qui est une checkbox pour nom "Aucun", Toutes les autres checkbox disponibles se decochent automatiquement . Par exemple si ma checkbox "#i3" qui a pour nom "inflammable" est coché mais que je coche "#i0" "Aucun" la checkbox "#i3" se décochent automatiquement. J'ai essayer de répondre à ma problématique via une méthode Jquery et voici mon code :
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
| <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
$(document).ready(function(){
$("#i0").click(function (e) {
if(this.prop('checked') == true) {
$(".test").each(function(e){
this.prop('checked', false);
});
}
});
});
</script>
<?php
$Pictogramme = new Pictogramme();
$result = $Pictogramme->TousPictogramme();
foreach($result as $data)
{
if(!is_null($lespictogrammes)){
if(in_array($data['NumeroPictogramme'],$lespictogrammes)){
$checked2 = "checked = 'checked'";
}else{
$checked2 ="";
}
}else{
$checked2="";
}
echo '<div style="display:inline-block;width:100px;padding:15px;">
<img src="'.IMAGES.$data['url_pictogramme'].'" alt="'.$data['sgh'].'" border="0" width="60" height="60"/>
<input class="test" id="i'.$data['NumeroPictogramme'].'" type="checkbox" name="choix[]" onClick="choix('.$data['NumeroPictogramme'].')" value="'.$data['NumeroPictogramme'].'" '.$checked2.'>
'.$data['sgh'].'
<br>
</div>';
} |
Exemple de checkbox :
Code:
1 2 3 4 5
| <input class="test" id="i0" type="checkbox" name="choix[]" onclick="choix(0)" value="0">
<input class="test" id="i1" type="checkbox" name="choix[]" onclick="choix(1)" value="1">
<input class="test" id="i2" type="checkbox" name="choix[]" onclick="choix(2)" value="2"> |
Merci de votre aide ^^.