formulaire deselectionner checkbox lors de selection dun autre checkbox

Eléphant du PHP | 331 Messages

09 mai 2009, 05:19

Bonjour,

jai une liste de 5 checkbox jaimerais que une fois quil y en a un de sélectionné si jen sélectionne un autre bien que le précédent soit déselectionné

exactement pour pour les radio button

Pouvez-vous m,aider?

Merci

Avatar du membre
Administrateur PHPfrance
Administrateur PHPfrance | 9782 Messages

09 mai 2009, 09:09

Bonjour,

J'ai trouvé cela via Google qui devrait correspondre à ce que tu cherche:

Code : Tout sélectionner

<HTML> <HEAD> <SCRIPT> function behaveLikeRadio(thisCheckBox) { if(!thisCheckBox.checked) return; var tableNode = thisCheckBox.parentNode.parentNode.parentNode.parentNode; var checkBoxes = tableNode.getElementsByTagName("INPUT"); for (var i=0; i<checkBoxes.length; i++) { if(checkBoxes[i].name != thisCheckBox.name && checkBoxes[i].type.toLowerCase() == "checkbox" && checkBoxes[i].id == thisCheckBox.id) { checkBoxes[i].checked = false; } } } </SCRIPT> </HEAD> <BODY> One record <TABLE border="1"> <TR> <TD><INPUT type="checkbox" name="Row1_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row1_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row2_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row2_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row3_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row3_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> </TABLE> <BR> Another record <TABLE border="1"> <TR> <TD><INPUT type="checkbox" name="Row1_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row1_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row2_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row2_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row3_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row3_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> </TABLE> </BODY> </HTML>
http://www.experts-exchange.com/Program ... 07624.html
Quand tout le reste a échoué, lisez le mode d'emploi...

Avatar du membre
Administrateur PHPfrance
Administrateur PHPfrance | 9782 Messages

09 mai 2009, 09:09

Bonjour,

J'ai trouvé cela via Google qui devrait correspondre à ce que tu cherche:

Code : Tout sélectionner

<HTML> <HEAD> <SCRIPT> function behaveLikeRadio(thisCheckBox) { if(!thisCheckBox.checked) return; var tableNode = thisCheckBox.parentNode.parentNode.parentNode.parentNode; var checkBoxes = tableNode.getElementsByTagName("INPUT"); for (var i=0; i<checkBoxes.length; i++) { if(checkBoxes[i].name != thisCheckBox.name && checkBoxes[i].type.toLowerCase() == "checkbox" && checkBoxes[i].id == thisCheckBox.id) { checkBoxes[i].checked = false; } } } </SCRIPT> </HEAD> <BODY> One record <TABLE border="1"> <TR> <TD><INPUT type="checkbox" name="Row1_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row1_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row2_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row2_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row3_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row3_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> </TABLE> <BR> Another record <TABLE border="1"> <TR> <TD><INPUT type="checkbox" name="Row1_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row1_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row2_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row2_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> <TR> <TD><INPUT type="checkbox" name="Row3_Col1" id="Col1" onclick="behaveLikeRadio(this)"></TD> <TD><INPUT type="checkbox" name="Row3_Col2" id="Col2" onclick="behaveLikeRadio(this)"></TD> </TR> </TABLE> </BODY> </HTML>
http://www.experts-exchange.com/Program ... 07624.html
Quand tout le reste a échoué, lisez le mode d'emploi...

Mammouth du PHP | 991 Messages

09 mai 2009, 09:09

Bonjour.
Pourquoi ne pas passer avec les boutons radios ?

Bye Hawk :roll:
DevOps, Symfony4, Hoa