IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Checkbox qui coche toutes les autres!


Sujet :

JavaScript

  1. #1
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Mai 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut Checkbox qui coche toutes les autres!
    Salut tout le monde,

    hier snakej et moi meme avons créer une page listant nos entrées de bdd avec une checkbox pour chaque ligne qui quand on la coche et validons, efface l'enregistrement.
    Aujourd'hui, nous voudrions créer en haut de notre tableau une checkbox qui quand on la coche, coche toutes les autres automatiquement! Cela nous eviterait en effet de nous amuser a tout cocher!

    Pourriez vous nous aider?

    Merci d'avance!
    Images attachées Images attachées  

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    D'après certaines recherche j'ai trouvé sa:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    function Check_all_box(frm)
    {
    	for (var i=0;i<frm.elements.length;i++)
    	{
     		var elem = frm.elements[i];
    		if ((elem.name != 'allbox') && (elem.type=='checkbox'))
    		{
    			elem.checked = frm.allbox.checked;
    		}
    	}
     
    }
    Je n'y pas encore réfléchie mais je vais regarder

  3. #3
    Expert éminent
    Avatar de Swoög
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    6 045
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 6 045
    Points : 8 339
    Points
    8 339
    Par défaut
    Salut !

    ce n'est pas possible en PHP

    Il vous faut vous tourner du côté de JavaScript (c'est d'ailleurs un problème récurrent, utiliser onchange et getElementsByTagName, ainsi que getAttribute)
    vous avez tous les éléments, faites quelques recherches
    Rédacteur "éclectique" (XML, Cours PHP, Cours JavaScript, IRC, Web...)
    Les Règles du Forum - Mon Site Web sur DVP.com (Développement Web, PHP, (X)HTML/CSS, SQL, XML, IRC)
    je ne répondrai à aucune question technique via MP, MSN ou Skype : les Forums sont là pour ça !!! Merci de me demander avant de m'ajouter à vos contacts sinon je bloque !
    pensez à la balise [ code ] (bouton #) et au tag (en bas)

  4. #4
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Mai 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    Au moins c'est clair et rapide ! Merci!

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    Moi sa m'interresse sa na pa laire très compliqué mais je ne sais pas ce que c'est:
    frm.elements. et length car je pense que ce sont des valeurs que je dois remplacer
    J'ai trouvé un 2eme code en php du site masi le java je ne le voit pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <label for="checkall_all">
    				<input type="checkbox" name="allbox" id="checkall_all" title="Cocher / Décocher tout" onclick="js_check_all(this.form)" />
    				</label>
    Je vous présente mon code en php:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    47
    <? include("connect.inc") ?>
    <html>
    <link rel="stylesheet" href="sitebn.css" type="text/css">
    <head>
    <META HTTP-EQUIV="Refresh" CONTENT="10";>
    <body>
    <form name="liste.php" action="unepers.php" method="post">
    <center><font color='red'><h1><i>Liste des réservations et gestion de la base de donnée</i></h1></center>
     
    <a href="effacertoutroulage.php"><br><font color='yellow'>Cliquez ici pour effacer toutes les réservations de votre liste</a></font></p>
     
     
    <table class="frm" align="center">
    <tr><th bgcolor='#99CCFF' width="1%">Numéro</th><th bgcolor='#99CCFF' width="3%">Grade</th><th bgcolor='#99CCFF' width="15%">Nom</th><th bgcolor='#99CCFF' width="15%">Prénom</th><th bgcolor='#99CCFF' width="5%">Téléphone</th><th bgcolor='#99CCFF' width="20%">Motif</th><th bgcolor='#99CCFF' width="2%">Jour</th><th bgcolor='#99CCFF' width="2%">Mois</th><th bgcolor='#99CCFF' width="4%">Année</th><th bgcolor='#99CCFF' width="3%">Heure début</th><th bgcolor='#99CCFF' width="2%">Minutes début</th><th bgcolor='#99CCFF' width="3%">Heure fin</th><th bgcolor='#99CCFF' width="3%">Minutes fin</th><th bgcolor='#99CCFF' width="6%">Effacer</th><th bgcolor='#99CCFF' width="10%">Tout sélectionner</th></tr>
     
     
    <?
    $resultat = mysql_query("select `id` , `grade` , `nom` , `prenom` , `telephone` , `motif` , `From_day` , `From_month` , `From_year` , `heuredebut` , `minutesdebut` , `heurefin` , `minutesfin` from roulage");
    while($ligne= mysql_fetch_object($resultat))
     
    {
    	echo "<tr onclick=\ onmouseover=\"this.className='over'\" onmouseout=\"this.className='out'\" class=\"out\">
    	<td><font color='yellow'><center>$ligne->id</center></font></td>
    	<td><font color='yellow'><center>$ligne->grade</center></font></td>
    	<td><font color='yellow'><center>$ligne->nom</center></font></td>
    	<td><font color='yellow'><center>$ligne->prenom</center></font></td>
    	<td><font color='yellow'><center>$ligne->telephone</center></font></td>
    	<td><font color='yellow'><center>$ligne->motif</center></font></td>
    	<td><font color='yellow'>$ligne->From_day</font></td>
    	<td><font color='yellow'>$ligne->From_month</font></td>
    	<td><font color='yellow'>$ligne->From_year</font></td>
    	<td><font color='yellow'><right>$ligne->heuredebut</right></font></td>
    	<td><font color='yellow'><left>$ligne->minutesdebut</left></font></td>
    	<td><font color='yellow'>$ligne->heurefin</font></td>
    	<td><font color='yellow'>$ligne->minutesfin</font></td>
    	<td><CENTER><INPUT TYPE='checkbox' value='$ligne->id' NAME='sel[]'/></CENTER></font></td>
    	<td>CENTER><INPUT TYPE='checkbox' value='$ligne->id' NAME='sel[]'/></CENTER></font></td>
    	</tr>";
    }
     
    ?>
     
    </table>
    </head>
    </body>
    </p><input type="submit" NAME="submit" value="Supprimer" action="unepers.php">
    </html>
    Nous avons une case check box à coté de tout selectionné pour tout selectioner les checkbox.
    Voilà si vous aviez la possibilité de m'aider pour tout sélectionner sa serai bien

  6. #6
    Membre régulier Avatar de youcef81
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    241
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mai 2006
    Messages : 241
    Points : 75
    Points
    75
    Par défaut
    essai ça :

    pour ton cas : check == nom de chekbox qui coche tous
    box nom des chebox a supprimer ..

    function cocherTous(check, box)
    {
    var b = box;
    if (check.checked == true) {
    for(var i = 0; i < b.length; i++)
    b[i].checked = true;
    } else {
    for(var i = 0; i < b.length; i++)
    b[i].checked = false;
    }
    }

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    j'ai essayé comme sa mais pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <table class="frm" align="center">
    <tr><th bgcolor='#99CCFF' width="1%">Numéro</th><th bgcolor='#99CCFF' width="3%">Grade</th><th bgcolor='#99CCFF' width="15%">Nom</th><th bgcolor='#99CCFF' width="15%">Prénom</th><th bgcolor='#99CCFF' width="5%">Téléphone</th><th bgcolor='#99CCFF' width="20%">Motif</th><th bgcolor='#99CCFF' width="2%">Jour</th><th bgcolor='#99CCFF' width="2%">Mois</th><th bgcolor='#99CCFF' width="4%">Année</th><th bgcolor='#99CCFF' width="3%">Heure début</th><th bgcolor='#99CCFF' width="2%">Minutes début</th><th bgcolor='#99CCFF' width="3%">Heure fin</th><th bgcolor='#99CCFF' width="3%">Minutes fin</th><th bgcolor='#99CCFF' width="6%">Effacer</th><th bgcolor='#99CCFF' width="10%">Tout sélectionner<?echo "<td class=\"".$style."\"><input type=\"checkbox\" name=\"sel[]\" value=\"".$i."\"/></td></tr>";?></th></tr>
    <script language="javascript">
    function checkAll(value){
          if(document.blast.checkall.checked){
              for(var i=0; i<value; i++){
                  document.forms[0].sel[][i].checked = true;
              }
          }
          else{
              for(var i=0; i<value; i++){
                  document.forms[0].sel[][i].checked = false;
              }
          }
      }
    </script>
    <?
    $resultat = mysql_query("select `id` , `grade` , `nom` , `prenom` , `telephone` , `motif` , `From_day` , `From_month` , `From_year` , `heuredebut` , `minutesdebut` , `heurefin` , `minutesfin` from roulage");
    while($ligne= mysql_fetch_object($resultat))

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    d'accord mais ce code Comment je l'organise dans ma page?
    Ou je mé le java et le checkbox? pour que sa marche?
    Merci

    Citation Envoyé par youcef81
    essai ça :

    pour ton cas : check == nom de chekbox qui coche tous
    box nom des chebox a supprimer ..

    function cocherTous(check, box)
    {
    var b = box;
    if (check.checked == true) {
    for(var i = 0; i < b.length; i++)
    b[i].checked = true;
    } else {
    for(var i = 0; i < b.length; i++)
    b[i].checked = false;
    }
    }

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    Comme je galère mais comme je galère j'ai tout lu sur le forum les topics résolu mais je ne m'en sors pas meme j'ai un peu lu les cours sur javascript je galère alors si quelqu'un est vraiment décider à m'aider sa serai cool.

    Merci

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    j'ai trouvé sa :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <th bgcolor='#99CCFF' width="10%">Tout sélectionner<input type="checkbox" name="checkboxall" value="checkbox" onClick=="if (document.getElementById('checkboxall').checked=true){Coche()}else{Decoche()};"></th></tr>
    <script language="javascript">
    function Coche(){
    	<%for i = 1 to (CptService-1)%>
    		document.getElementById('checkboxService<%=i%>').checked=true;
    		document.getElementById('Service<%=i%>').disabled=false;
    	<%next%>
    	<%for i = 1 to (CptDomaine-1)%>
    		document.getElementById('checkboxDomaine<%=i%>').checked=true;
    		document.getElementById('Domaine<%=i%>').disabled=false;
    	<%next%>
    }
    function Decoche(){
    	<%for i = 1 to (CptService-1)%>
    		document.getElementById('checkboxService<%=i%>').checked=false;
    		document.getElementById('Service<%=i%>').disabled=true;
    	<%next%>
    	<%for i = 1 to (CptDomaine-1)%>
    		document.getElementById('checkboxDomaine<%=i%>').checked=false;
    		document.getElementById('Domaine<%=i%>').disabled=true;
    	<%next%>
    }
    <?
    $resultat = mysql_query("select `id` , `grade` , `nom` , `prenom` , `telephone` , `motif` , `From_day` , `From_month` , `From_year` , `heuredebut` , `minutesdebut` , `heurefin` , `minutesfin` from roulage");
    while($ligne= mysql_fetch_object($resultat))
     
    {
    	echo "<tr onclick=\ onmouseover=\"this.className='over'\" onmouseout=\"this.className='out'\" class=\"out\">
    	<td><font color='yellow'><center>$ligne->id</center></font></td>
    	<td><font color='yellow'><center>$ligne->grade</center></font></td>
    	<td><font color='yellow'><center>$ligne->nom</center></font></td>
    	<td><font color='yellow'><center>$ligne->prenom</center></font></td>
    	<td><font color='yellow'><center>$ligne->telephone</center></font></td>
    	<td><font color='yellow'><center>$ligne->motif</center></font></td>
    	<td><font color='yellow'>$ligne->From_day</font></td>
    	<td><font color='yellow'>$ligne->From_month</font></td>
    	<td><font color='yellow'>$ligne->From_year</font></td>
    	<td><font color='yellow'><right>$ligne->heuredebut</right></font></td>
    	<td><font color='yellow'><left>$ligne->minutesdebut</left></font></td>
    	<td><font color='yellow'>$ligne->heurefin</font></td>
    	<td><font color='yellow'>$ligne->minutesfin</font></td>
    	<td><CENTER><INPUT TYPE='checkbox' value='checkbox' NAME='checkboxAll'/></CENTER></td>
    	<td><CENTER><INPUT TYPE='checkbox' value='$ligne->id' NAME='checkboxAll'/></CENTER></td>
    	</tr>";
    </script>

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    comme vous pouvez le remarqué j'ai fes des modification a aprtir de ma derniere colone du tableau mais je ne c'est pas si c'est sa.

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 183
    Points : 56
    Points
    56
    Par défaut
    J'ai trouvé ce code la aussi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    function SetAllCheckBoxes(FormName, FieldName, CheckValue)
    {
    	if(!document.forms[FormName])
    		return;
    	var objCheckBoxes = document.forms[FormName].elements[FieldName];
    	if(!objCheckBoxes)
    		return;
    	var countCheckBoxes = objCheckBoxes.length;
    	if(!countCheckBoxes)
    		objCheckBoxes.checked = CheckValue;
    	else
    		// set the check value for all check boxes
    		for(var i = 0; i < countCheckBoxes; i++)
    			objCheckBoxes[i].checked = CheckValue;
    }

Discussions similaires

  1. [AC-2003] Case à cocher qui cochent toutes les autres
    Par lucas-18 dans le forum IHM
    Réponses: 4
    Dernier message: 27/10/2010, 09h44
  2. checkbox qui coche tous les checkbox d'une table
    Par solarien dans le forum JSF
    Réponses: 4
    Dernier message: 19/09/2008, 08h05
  3. [JFrame] Désiconifier toutes les autres fenêtres en même temps
    Par stoukou dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 07/10/2005, 12h01
  4. Réponses: 1
    Dernier message: 16/02/2005, 12h04
  5. Réponses: 2
    Dernier message: 09/07/2003, 14h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo