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] Code pour cocher toutes les cases


Sujet :

JavaScript

  1. #1
    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 [checkbox] Code pour cocher toutes les cases
    Salut j'en cré un nouveau pour que tout soit compréhensible:
    j'ai trouvé un code que je comprend:
    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
    <html><head>
    <title>checkbox maître</title>
    <script>
    //checkbox ou une liste de checkbox.
    function selectall(cas,choix){
      //test si on a plusieur ligne
      if(choix.length>0){
        if (cas.checked){
          for (var i=0; i<choix.length;i++){
            choix[i].checked=true
          }
        }
        else{
          for (var i=0; i<choix.length;i++){
            choix[i].checked=false
          }
        }
      }
      else{
        if (cas.checked){
          choix.checked=true
        }
        else{
          choix.checked=false
        }
      }
    }</script>
    </head>
     
    <body>
    <form name="monform">
    <input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)">
    puis un liste de checkbox
    <input type="checkbox" name="choix" value="1">
    <input type="checkbox" name="choix" value="2">
    <input type="checkbox" name="choix" value="3"></form>
    </body></html>
    Voici enfin une explication sur ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Petit explication sur l'utilisation:
    dans un formulaire on place une checkbox "maitre" en lui associant la fonction selectall sur l'action onclick:
    <input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)">
    puis un liste de checkbox
    <input type="checkbox" name="choix" value="1">
    <input type="checkbox" name="choix" value="2">
    <input type="checkbox" name="choix" value="3">
    et voici mon code une fois modifier:
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    <? include("connect.inc") ?>
    <html>
    <link rel="stylesheet" href="sitebn.css" type="text/css">
    <head>
    <META HTTP-EQUIV="Refresh" CONTENT="20";>
    <script>:D 
    //checkbox ou une liste de checkbox.
    function selectall(cas,choix){
      //test si on a plusieur ligne
      if(choix.length>0){
        if (cas.checked){
          for (var i=0; i<choix.length;i++){
            choix[i].checked=true
          }
        }
        else{
          for (var i=0; i<choix.length;i++){
            choix[i].checked=false
          }
        }
      }
      else{
        if (cas.checked){
          choix.checked=true
        }
        else{
          choix.checked=false
        }
      }
    }</script>:D 
    <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:D <form name="monform">
    <input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)">:D 
     
    </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>
        :D <td><CENTER><INPUT TYPE='checkbox' value='checkbox' name='choix'/></CENTER></td>
        <td><CENTER><INPUT TYPE='checkbox' value='$ligne->id' name='choix'/></CENTER></td>:D 
        </tr>";
    }
     
    ?>
     
    </table>
    </head>
    </body>
    </p><input type="submit" NAME="submit" value="Supprimer" action="unepers.php">
    </html>
    j'ai mis des smiley pour vous montré ou j'ai mis le code.
    je pense que sa ne marche pas car mes checkbox sont dans du php.
    j'aimerai qu'on m'aide a trouvé une solution dans mon code j'y suis presque merci de m'aider!

  2. #2
    Membre éclairé
    Avatar de kankrelune
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    763
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 763
    Points : 858
    Points
    858
    Par défaut
    Pas la peine de poster un nouveau sujet toutes les deux minutes... .. !

    Pour la peine... Google est ton ami... .. .

    @ tchaOo°

  3. #3
    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
    ok mais le problème avec moi et google c'est que sa ne marche jamais
    bref google et moi sa fé 50!!
    j'ai regardé le 3eme c'est pas mal aussi mais je preferai le 4eme je vais regarder et essayer.
    merci quand meme.
    Mais le code que j'ai mis en haut et bon normalement il y a juste a l'intégré dans mon code qui est ma difficulté.

  4. #4
    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
    Sa y est je suis arriver il fo juste que sa efface!!!
    sa me rend fou

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    Envoie ton code si t'arrives pas ...dois y avoir un vieux probleme comme hier!

  6. #6
    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
    Suis bien mes modifications:
    1er modification ajout du script
    2eme modification rajout d'une case à cocher
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <CENTER><INPUT TYPE='checkbox' value='$ligne->id' name='list' onClick="this.value=check(this.form.list)"/></CENTER>
    3eme modifications la derniere ligne de mon echo du php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    	<td><CENTER><INPUT TYPE='checkbox' value='$ligne->id' name='list'/></CENTER></td>
    4eme modifications:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    if(isset($_POST['submit']))
        {
              $id=$_POST['list'];  
              for ($i = 0; $i < count($id); $i++)
                 {
                      $req = "DELETE FROM roulage WHERE id  = '$id[$i]'";
                     mysql_query ($req) or die(mysql_error());
                 }
        }
    ?>
    j'ai remplacé le sel par le list

    voilà j'espere que tu trouvera car la c'est un truc tout c?n.

  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 oublié le script
    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
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
      for (i = 0; i < field.length; i++) {
      field[i].checked = true;}
      checkflag = "true";
      return "Tout décocher"; }
    else {
      for (i = 0; i < field.length; i++) {
      field[i].checked = false; }
      checkflag = "false";
      return "Tout cocher"; }
    }
    //  End -->
    </script>

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    As tu essayé de mettre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    name='list[]'   
    //au lieu de
    name='list'

  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
    c'est sa tu as raison mais ensuite mon code javascrip ne marche plus.
    Je ne voit pas ou sa plante j'ai changé list par list[] de par tout , mais la selection ne marche pas.
    essaye avec ton code pour voire si sa viens de moi ou du code

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    Ca c'est embetant surtout que je connais rien au js

    Ton javascript, tu la mis au debut du fichier d'hier?

  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
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    <? include("connect.inc") ?>
    <html>
    <link rel="stylesheet" href="sitebn.css" type="text/css">
    <head>
    <body>
    <META HTTP-EQUIV="Refresh" CONTENT="20";>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var checkflag = "false";
    function check(field) {
    if (checkflag == "false") {
      for (i = 0; i < field.length; i++) {
      field[i].checked = true;}
      checkflag = "true";
      return "Tout décocher"; }
    else {
      for (i = 0; i < field.length; i++) {
      field[i].checked = false; }
      checkflag = "false";
      return "Tout cocher"; }
    }
    //  End -->
    </script>
     
    <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="10%">Tout sélectionner<CENTER><INPUT TYPE='checkbox' value='$ligne->id' name='list[]' onClick="this.value=check(this.form.list[])"/></CENTER>
     
    </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='list[]'/></CENTER></td>
    	</tr>";
    }
     
    ?>
     
    </table>
    </head>
    </body>
    </p><input type="submit" NAME="submit" value="Supprimer" action="unepers.php"></p>
    </html>

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    pourquoi cette ligne a la fin ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <input type="submit" NAME="submit" value="Supprimer" action="unepers.php">
    Ne serait ce pas plutot


  13. #13
    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 capté le blem sa vien de sa [] il fo trouvé autre chose que sa

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    ta mis le </form> en bas de page ? comme jtai dit avt ?

    J'ai pris ton code mais je n'ai pas la checkbox qui ^permet de tt selectionner ... LOL

  15. #15
    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
    Mon bouton a la fin permet de supprimé les lignes selectionnées.

  16. #16
    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 me rend fou j'arrive a selectionner mais quand je fé les modif pour effacer plus rien ne marche ben sa efface mais on ne peux plus selectionné toutes les cases a coché!!

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 51
    Points
    51
    Par défaut
    exact mais ferme le form qd meme!
    et pourquoi as tu mis 2 fois la action ? Je suppose que tout ca est dans le meme form, donc ca ne sert a rien de le mettre deux fois!

  18. #18
    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
    Je continue mon poste nouvelle mise a jour:
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    <? include("connect.inc") ?>
    <html>
    <link rel="stylesheet" href="sitebn.css" type="text/css">
    <head>
    <body>
    <META HTTP-EQUIV="Refresh" CONTENT="20";>
    <script>
    //checkbox ou une liste de checkbox.
    function selectall(cas,choix){
      //test si on a plusieur ligne
      if(choix.length>0){
        if (cas.checked){
          for (var i=0; i<choix.length;i++){
            choix[i].checked=true
          }
        }
        else{
          for (var i=0; i<choix.length;i++){
            choix[i].checked=false
          }
        }
      }
      else{
        if (cas.checked){
          choix.checked=true
        }
        else{
          choix.checked=false
        }
      }
    }</script>
     
    <form name="monform" 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="10%">Tout sélectionner<CENTER><input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)"></CENTER>
     
    </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='choix[]'/></CENTER></td>
    	</tr>";
    }
     
    ?>
    </table>
    </head>
    </body>
    </p><input type="submit" NAME="submit" value="Supprimer" action="unepers.php"></p>
    </form>
    </html>

    Ajout d'un script 7eme ligne cocher et decocher a case.
    Dans mon tableau (l39)derniere ligne création de la case à coché a côté de "tout sélectionner" <input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)"> ceci est la checkbox maitre

    Ensuite dans mon php j'ai pour code checkbox
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <INPUT TYPE='checkbox' value='$ligne->id' name='choix[]'/>
    tout ceci m'emene sur une page qui me confirme l'effacement:
    voici son code :
    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
    <html>
    <body>
    <head>
    <link rel="stylesheet" href="sitebn.css" type="text/css">
    <font color='yellow'>
    <?php
     $bdd="bntoulon";
     mysql_connect("localhost","root","");
     mysql_select_db($bdd);
     
     
    if(isset($_POST['submit']))
        {
              $id=$_POST['choix'];  
              for ($i = 0; $i < count($id); $i++)
                 {
                      $req = "DELETE FROM roulage WHERE id  = '$id[$i]'";
                     mysql_query ($req) or die(mysql_error());
                 }
        }
    ?>
    </p>
    <a href="liste.php"><font color='yellow'>Revenir à l'accueil</a></font></p>
    </head>
    </body>
    </html>

    Lisez bien:
    Logiquement le code que je vous ai donné me permet:
    -de coché et decoché ainsi que supprimé les cases coché.

    La mon code me permet de coché une case et de la supprimé(comme si je n'avais rien mis)

    Pour tout cocher et decoché il faut que j'enleve mes [] de mon "name" dans ma ligne <INPUT TYPE='checkbox' value='$ligne->id' name='choix[]'/>
    qui se trouve dans mon code php mais le problème c'est que je ne peux pas supprimer.

    Si je laisse les [] dans mon "name" je ne peux pas tout sélectionner mais seulement sélectionner une case après l'autre et ensuite supprimé.

    J'ai essayé de mettre des [] après tous les mots finissant par choix mais sa ne marche pas.

    Voilà j'espere que vous pouvez m'aider

  19. #19
    Membre expérimenté

    Homme Profil pro
    Inscrit en
    Janvier 2004
    Messages
    1 249
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 1 249
    Points : 1 565
    Points
    1 565
    Par défaut
    mmhhh

    a mon avis faut commencer par enlever tout le html inutile pour y voir plus clair (scroller de 10 pages pour voir l'appel de la methode... hum...)

    Tu n'a besoin d'avoir que :
    *html
    *head
    * script
    * /head
    *body
    *form
    *input de cocher/decocher tout
    * input de coche individuelle (dans boucle php, celle la tu peux la laisser
    * input submit si tu veux
    * /form et autres balises fermante

    Tant qu'on y est, enleve le meta refresh aussi... hum...

    Enleve tout ce qui est font, td, tr, table, center, etc... qui nuisent a la lisibilité et ne donnent pas envie de t'aider ;o)

    De plus, il ne sert absoluement a rien d'afficher ici du code php pour l'instant, car si j'ai bien compris ton probleme est un probleme de cocher/decocher tout, donc tu fait un clic droit sur ton navigateur, voir la source, tu copie le html, tu le nettoie pour enlever tout le code inutile, tu le copie dans un fichier .html et tu test et met au point le cocher/decocher en javascript. Puis tu reportes tes modifications dans ton 1er fichier.

    De plus, il me semble que form.all ne fonctionne que sous ie, a proscrire donc.
    JS permet de recuperer facilement des controles par leurs type (getElementsByTagName) puis tu peux faire un filtre sur le nom ou sur un attribut class par exemple.

    Enfin, tes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if (condition) {
    var=true;
    }
    else {
    var=false;
    }
    s'abregent en :

    A mon avis, on posant tout ca on y verra deja vachement plus clair

  20. #20
    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
    Pas de problème il suffit de demander voici mon script en javascript qui marche bien:
    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
    <script>
    //checkbox ou une liste de checkbox.
    function selectall(cas,choix){
      //test si on a plusieur ligne
      if(choix.length>0){
        if (cas.checked){
          for (var i=0; i<choix.length;i++){
            choix[i].checked=true
          }
        }
        else{
          for (var i=0; i<choix.length;i++){
            choix[i].checked=false
          }
        }
      }
      else{
        if (cas.checked){
          choix.checked=true
        }
        else{
          choix.checked=false
        }
      }
    }</script>

    Création de ma case a coché maitre à la fin de mon tableau:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tout sélectionner<CENTER><input type="checkbox" name="all" onclick="selectall(document.monform.all,document.monform.choix)"></CENTER>
    Et voici ma partie ou les cases à cocher se rajoute automatiquement dès qu'il y a une nouvelle ligne.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td><CENTER><INPUT TYPE='checkbox' value='$ligne->id' name='choix[]'/></CENTER></td>
    Voici ma page suivant quiand je décide de tout supprimer:
    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
    <?php
     $bdd="bntoulon";
     mysql_connect("localhost","root","");
     mysql_select_db($bdd);
     
     
    if(isset($_POST['submit']))
        {
              $id=$_POST['choix'];  
              for ($i = 0; $i < count($id); $i++)
                 {
                      $req = "DELETE FROM roulage WHERE id  = '$id[$i]'";
                     mysql_query ($req) or die(mysql_error());
                 }
        }
    ?>


    et voici le problème qui se pose:
    Lisez bien:
    Logiquement le code que je vous ai donné me permet:
    -de coché et decoché ainsi que supprimé les cases coché.

    La mon code me permet de coché une case et de la supprimé(comme si je n'avais rien mis)

    Pour tout cocher et decoché il faut que j'enleve mes [] de mon "name" dans ma ligne <INPUT TYPE='checkbox' value='$ligne->id' name='choix[]'/>
    qui se trouve dans mon code php mais le problème c'est que je ne peux pas supprimer.

    Si je laisse les [] dans mon "name" je ne peux pas tout sélectionner mais seulement sélectionner une case après l'autre et ensuite supprimé.

    J'ai essayé de mettre des [] après tous les mots finissant par choix mais sa ne marche pas.

    Merci @tte à l'heure

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Fonction non définie (alors qu'elle l'est) - Cocher toutes les cases
    Par navis84 dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 22/09/2006, 12h02
  2. Cocher toutes les cases à cocher d'un formulaire
    Par petitloup71 dans le forum Access
    Réponses: 12
    Dernier message: 14/09/2006, 10h37
  3. cocher toutes les cases
    Par tabulaire dans le forum Access
    Réponses: 1
    Dernier message: 17/08/2006, 12h08
  4. cocher toutes les cases à cocher
    Par philippe123 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 01/09/2005, 18h13
  5. [VB.NET] Datagrid + CheckBox : Cocher toutes les cases
    Par sirex007 dans le forum ASP.NET
    Réponses: 5
    Dernier message: 24/05/2004, 15h33

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