NerOcrO 0 Report post Posted February 21, 2006 Salut, Voici ma fonction JS pour cocher/décocher des checkbox : function toutCocher(formulaire,nom) { nbr=(formulaire.elements.length)/7; for(i=0;i<nbr;++i) { if(formulaire.nom+i+.substring(0,nom+i+.length) == nom+i) formulaire.nom+i+.checked = !formulaire.nom+i+.checked; } }</script> Pour la partie HTML, j'ai un lien avec cette fonction qui envoie document.getElementById('content') pour la variable formulaire et cbX (X étant incrémenté pour toutes les checkbox) pour la variable nom. Donc ce code ne fonctionne pas, j'vois pas pourquoi. De plus quand je fais alert(formulaire.nom+i); -> j'ai undefined alors que si je marque alert(formulaire.cb0);, ça fonctionne. Merci par avance. Share this post Link to post Share on other sites
astrofiles 0 Report post Posted February 21, 2006 Personnellement j'utilise le code suivant, peut être cela t'aidera En supposant que ton checkbox s'intitule choix <input type=\"checkbox\" name=\"choix[]\" ..... le lien pour tout selectionner sera ...... onclick=\"selectAll(this.form('choix[]'),true)\"> et la fonction javascript function selectAll(cbList,bSelect) { for (var i=0; i<cbList.length; i++) cbList[i].selected = cbList[i].checked = bSelect} Voila Share this post Link to post Share on other sites
NerOcrO 0 Report post Posted February 21, 2006 Justement non, mes 'name' sont du style cb0, cb1, cbX, comme dit plus haut. Mais ce n'est pas grave, j'ai résolu mon problème en utilisant 'elements' de javascript. Share this post Link to post Share on other sites
NorSeb 0 Report post Posted February 21, 2006 Salut, Au lieu de faire : for(i=0;i<nbr;++i) { if(formulaire.nom+i+.substring(0,nom+i+.length) == nom+i) formulaire.nom+i+.checked = !formulaire.nom+i+.checked; } je ferais ca : var case;for(i=0;i<nbr;++i) { case = 'formulaire.nom'+i; if(case.substring(0,nom+i+.length) == 'nom'+i) case.checked = !fcase.checked; } Share this post Link to post Share on other sites