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 :

Tableau de 90 cases à cocher


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 113
    Par défaut Tableau de 90 cases à cocher
    bonjour
    j'aimerai crée un tableau ou je clique dessus me remplis chiffre corespondant
    exemple cellule de de tableau de 1 a 90
    chiffre griser en gris est en cliquant dessus ,devient noir
    est mis en mémoire dans un tableau..
    ensuite en pressant un bouton ok par exemple
    me sort les chiffre que je n'ai pas sélectionner..
    je sais pas si c'est plus simple avec une page internet ou avec un excell?
    merci
    bon le tableau avec dreamveaer je le cree facilement..
    mais après cliquer sur le tableau est mèmorser le chiffre ca je trouve pas
    merci

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    1- Prends un papier et un crayon.
    Écris tout ça "au propre", et en détails.

    Ça s'appelle un cahier des charges.

    2- Quand ce sera fait :
    Essaie de trouver TOI-MEME des idees, des débuts de solutions, les langages nécessaires (PHP, JavaScript,...)...
    ...fais une recherche, avec des mots clé "choisis"

    3- (de préférence) commence à coder.

    4- si tu as des soucis avec TON code : poste alors ta question (précise) ici.
    Pas avant.
    Merci.


    N.B. et évite, comme dans ton précédent message, d'écrire en "style télégraphique".
    Fais de "vraies phrases".

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 113
    Par défaut plus de info
    voici un debut code

    Code html : 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
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td width="15" align="center">1</td>
      <td width="15" align="center"><input type="checkbox" id="C1" name="C1"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">11</td>
      <td width="15" align="center"><input type="checkbox" id="C11" name="C11"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">21</td>
      <td width="15" align="center"><input type="checkbox" id="C21" name="C21"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">31</td>
      <td width="15" align="center"><input type="checkbox" id="C31" name="C31"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">41</td>
      <td width="15" align="center"><input type="checkbox" id="C41" name="C41"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">51</td>
      <td width="15" align="center"><input type="checkbox" id="C51" name="C51"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">61</td>
      <td width="15" align="center"><input type="checkbox" id="C61" name="C61"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">71</td>
      <td width="15" align="center"><input type="checkbox" id="C71" name="C71"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      <td width="15" align="center">81</td>
      <td width="15" align="center"><input type="checkbox" id="C81" name="C81"  value="1"></td>
      <td width="10" align="center">&nbsp;</td>
      </tr>
    est ainsi de suite jusqua 90

    voila ensuite je sais pas comment faire un bouton
    sortir la sélection ou les nombre non sélectionner

    merci
    code pour effacer la sélection
    Code html : 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
    <td>
    <p><br>
     
      </select><br><br><a href="javascript:vider();">Vider la grille</a></p>
     
    </td></tr></table>
    <input type="hidden" name="validateur" value="-1"><br>
    	<button type="submit" class="btn btn-default">Envoyer</button>
    <br>
     
    <script language="Javascript" type="text/JavaScript">
    function vider(){
                    var i=0;
                    for (i=1;i<=90;i++) {
                            var cellule = 'C'+i;
                            document.getElementById(cellule).checked=false;
                    }
                    }
                    </script>

  4. #4
    Expert confirmé
    Avatar de Watilin
    Homme Profil pro
    En recherche d'emploi
    Inscrit en
    Juin 2010
    Messages
    3 094
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : En recherche d'emploi

    Informations forums :
    Inscription : Juin 2010
    Messages : 3 094
    Par défaut
    Citation Envoyé par giovanni Voir le message
    bon le tableau avec dreamveaer je le cree facilement..
    Assure-toi que tu utilises la dernière version de DW et qu’il est à jour. Paramètre-le pour qu’il produise du HTML 5 avec des feuilles de style externes.

    Si tu ne présentes pas du code qui reflète les bonnes pratiques actuelles, tu auras du mal à trouver des gens qui voudront bien t’aider.

    Quant au script :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function vider() {
      "use strict";
     
      let allBoxes = document.querySelectorAll("input[type=checkbox]");
      for (let box of allBoxes) {
        box.checked = false;
      }
    }
    Voir :
    La FAQ JavaScript – Les cours JavaScript
    Touche F12 = la console → l’outil indispensable pour développer en JavaScript !

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 113
    Par défaut voila le site pour exemple
    https://giovannich1965.000webhostapp.com/

    comme vous pouvez voir le effacer fonctionne
    le reste non qui me sort la sélection ou inverser la sélection
    au fait c'est des copie de texte pas utiliser le dreamweaver
    merci

  6. #6
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    voici un code fonctionnel : https://codepen.io/jreaux62/pen/XBMxBd

    Code html : 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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    <form id="form90cases" method="post" action="">
      <table>
        <tr>
          <td><label>1<input type="checkbox" name="cb[1]" value="1" /></label></td>
          <td><label>11<input type="checkbox" name="cb[11]" value="1" /></label></td>
          <td><label>21<input type="checkbox" name="cb[21]" value="1" /></label></td>
          <td><label>31<input type="checkbox" name="cb[31]" value="1" /></label></td>
          <td><label>41<input type="checkbox" name="cb[41]" value="1" /></label></td>
          <td><label>51<input type="checkbox" name="cb[51]" value="1" /></label></td>
          <td><label>61<input type="checkbox" name="cb[61]" value="1" /></label></td>
          <td><label>71<input type="checkbox" name="cb[71]" value="1" /></label></td>
          <td><label>81<input type="checkbox" name="cb[81]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>2<input type="checkbox" name="cb[2]" value="1" /></label></td>
          <td><label>12<input type="checkbox" name="cb[12]" value="1" /></label></td>
          <td><label>22<input type="checkbox" name="cb[22]" value="1" /></label></td>
          <td><label>32<input type="checkbox" name="cb[32]" value="1" /></label></td>
          <td><label>42<input type="checkbox" name="cb[42]" value="1" /></label></td>
          <td><label>52<input type="checkbox" name="cb[52]" value="1" /></label></td>
          <td><label>62<input type="checkbox" name="cb[62]" value="1" /></label></td>
          <td><label>72<input type="checkbox" name="cb[72]" value="1" /></label></td>
          <td><label>82<input type="checkbox" name="cb[82]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>3<input type="checkbox" name="cb[3]" value="1" /></label></td>
          <td><label>13<input type="checkbox" name="cb[13]" value="1" /></label></td>
          <td><label>23<input type="checkbox" name="cb[23]" value="1" /></label></td>
          <td><label>33<input type="checkbox" name="cb[33]" value="1" /></label></td>
          <td><label>43<input type="checkbox" name="cb[43]" value="1" /></label></td>
          <td><label>53<input type="checkbox" name="cb[53]" value="1" /></label></td>
          <td><label>63<input type="checkbox" name="cb[63]" value="1" /></label></td>
          <td><label>73<input type="checkbox" name="cb[73]" value="1" /></label></td>
          <td><label>83<input type="checkbox" name="cb[83]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>4<input type="checkbox" name="cb[4]" value="1" /></label></td>
          <td><label>14<input type="checkbox" name="cb[14]" value="1" /></label></td>
          <td><label>24<input type="checkbox" name="cb[24]" value="1" /></label></td>
          <td><label>34<input type="checkbox" name="cb[34]" value="1" /></label></td>
          <td><label>44<input type="checkbox" name="cb[44]" value="1" /></label></td>
          <td><label>54<input type="checkbox" name="cb[54]" value="1" /></label></td>
          <td><label>64<input type="checkbox" name="cb[64]" value="1" /></label></td>
          <td><label>74<input type="checkbox" name="cb[74]" value="1" /></label></td>
          <td><label>84<input type="checkbox" name="cb[84]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>5<input type="checkbox" name="cb[5]" value="1" /></label></td>
          <td><label>15<input type="checkbox" name="cb[15]" value="1" /></label></td>
          <td><label>25<input type="checkbox" name="cb[25]" value="1" /></label></td>
          <td><label>35<input type="checkbox" name="cb[35]" value="1" /></label></td>
          <td><label>45<input type="checkbox" name="cb[45]" value="1" /></label></td>
          <td><label>55<input type="checkbox" name="cb[55]" value="1" /></label></td>
          <td><label>65<input type="checkbox" name="cb[65]" value="1" /></label></td>
          <td><label>75<input type="checkbox" name="cb[75]" value="1" /></label></td>
          <td><label>85<input type="checkbox" name="cb[85]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>6<input type="checkbox" name="cb[6]" value="1" /></label></td>
          <td><label>16<input type="checkbox" name="cb[16]" value="1" /></label></td>
          <td><label>26<input type="checkbox" name="cb[26]" value="1" /></label></td>
          <td><label>36<input type="checkbox" name="cb[36]" value="1" /></label></td>
          <td><label>46<input type="checkbox" name="cb[46]" value="1" /></label></td>
          <td><label>56<input type="checkbox" name="cb[56]" value="1" /></label></td>
          <td><label>66<input type="checkbox" name="cb[66]" value="1" /></label></td>
          <td><label>76<input type="checkbox" name="cb[76]" value="1" /></label></td>
          <td><label>86<input type="checkbox" name="cb[86]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>7<input type="checkbox" name="cb[7]" value="1" /></label></td>
          <td><label>17<input type="checkbox" name="cb[17]" value="1" /></label></td>
          <td><label>27<input type="checkbox" name="cb[27]" value="1" /></label></td>
          <td><label>37<input type="checkbox" name="cb[37]" value="1" /></label></td>
          <td><label>47<input type="checkbox" name="cb[47]" value="1" /></label></td>
          <td><label>57<input type="checkbox" name="cb[57]" value="1" /></label></td>
          <td><label>67<input type="checkbox" name="cb[67]" value="1" /></label></td>
          <td><label>77<input type="checkbox" name="cb[77]" value="1" /></label></td>
          <td><label>87<input type="checkbox" name="cb[87]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>8<input type="checkbox" name="cb[8]" value="1" /></label></td>
          <td><label>18<input type="checkbox" name="cb[18]" value="1" /></label></td>
          <td><label>28<input type="checkbox" name="cb[28]" value="1" /></label></td>
          <td><label>38<input type="checkbox" name="cb[38]" value="1" /></label></td>
          <td><label>48<input type="checkbox" name="cb[48]" value="1" /></label></td>
          <td><label>58<input type="checkbox" name="cb[58]" value="1" /></label></td>
          <td><label>68<input type="checkbox" name="cb[68]" value="1" /></label></td>
          <td><label>78<input type="checkbox" name="cb[78]" value="1" /></label></td>
          <td><label>88<input type="checkbox" name="cb[88]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>9<input type="checkbox" name="cb[9]" value="1" /></label></td>
          <td><label>19<input type="checkbox" name="cb[19]" value="1" /></label></td>
          <td><label>29<input type="checkbox" name="cb[29]" value="1" /></label></td>
          <td><label>39<input type="checkbox" name="cb[39]" value="1" /></label></td>
          <td><label>49<input type="checkbox" name="cb[49]" value="1" /></label></td>
          <td><label>59<input type="checkbox" name="cb[59]" value="1" /></label></td>
          <td><label>69<input type="checkbox" name="cb[69]" value="1" /></label></td>
          <td><label>79<input type="checkbox" name="cb[79]" value="1" /></label></td>
          <td><label>89<input type="checkbox" name="cb[89]" value="1" /></label></td>
        </tr>
        <tr>
          <td><label>10<input type="checkbox" name="cb[10]" value="1" /></label></td>
          <td><label>20<input type="checkbox" name="cb[20]" value="1" /></label></td>
          <td><label>30<input type="checkbox" name="cb[30]" value="1" /></label></td>
          <td><label>40<input type="checkbox" name="cb[40]" value="1" /></label></td>
          <td><label>50<input type="checkbox" name="cb[50]" value="1" /></label></td>
          <td><label>60<input type="checkbox" name="cb[60]" value="1" /></label></td>
          <td><label>70<input type="checkbox" name="cb[70]" value="1" /></label></td>
          <td><label>80<input type="checkbox" name="cb[80]" value="1" /></label></td>
          <td><label>90<input type="checkbox" name="cb[90]" value="1" /></label></td>
        </tr>
      </table>
     
      <button type="reset" name="btn-reset">Vider la grille</button>
      <button type="button" name="btn-invert">Inverser la sélection</button>
      <button type="submit" name="btn-submit">Envoyer</button>
    </form>
    Code css : 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
    #form90cases table {
      border-collapse: collapse;
    }
    #form90cases table td {
      padding: 0;
      border: 1px solid #ccc;
      text-align: right;
    }
    #form90cases table td label {
      display: inline-block;
      padding: 7px 1px;
      color: #999;
      cursor:pointer;
    }
    #form90cases table td label.on {
      color: green;
      font-weight: bold;
      background: #daf7a6;
    }
    Code JavaScript : 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
    "use strict";
    // 1- checkbox
    let allBoxes = document.querySelectorAll('#form90cases input[type=checkbox]');
    allBoxes.forEach(function(box) {
      box.addEventListener("click", function(){ 
        box.parentNode.classList.toggle('on');
      });
    });
    // 2- Reset (Vider la grille)
    let btnReset = document.querySelector('#form90cases button[name="btn-reset"]');
    btnReset.addEventListener("click", function(){ 
      for (let box of allBoxes) {
        box.checked = false; // décoche la sélection
        box.parentNode.classList.remove('on');
      }
    });
    // 3- inverser la sélection
    let btnInvert = document.querySelector('#form90cases button[name="btn-invert"]');
    btnInvert.addEventListener("click", function(){ 
      for (let box of allBoxes) {
        box.checked = !box.checked; 
        box.parentNode.classList.toggle('on');
      }
    });

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 113
    Par défaut voila
    j'ai mis votre script sur le site tout ok sauf le envoyer ne va pas ..mais je sais pas pourquoi
    possible d'ajouter combien de chiffre selection ?
    merci

    https://giovannich1965.000webhostapp.com/

  8. #8
    Invité
    Invité(e)
    Par défaut
    @Watilin
    Il te manque juste le changement de couleur des cases cochées

    Concernant mon code (lui aussi sans jQuery), l'essentiel du JavaScript consiste à changer la classe "on" sur les <label> (et pour l'inversion) !
    Et les trois boutons montrent les 3 types possibles : reset, button et submit !

    @giovanni
    ...possible d'ajouter combien de chiffre selection ?...
    Je ne comprends pas tes phrases...
    ... mais je répondrais : tous.

    Au clic sur le bouton "Envoyer", on est censé faire quoi ??


    Si c'est une récupération via un ficher PHP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    < input ... name="cb[9]" value="1" />
    Toutes les checkbox ont le même name.
    Les crochets indiquent un tableau de valeurs (array).

    Code php : 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
    if( isset($_POST['btn-submit']) )
    {
    	// on récupère TOUTES les cases COCHEES (uniquement)
    	$cb_all = ( !empty($_POST['cb']) )? $_POST['cb'] : []; // array
     
    	// affichage :
    	foreach( $cb_all as $cb => $val ) // ici, la valeur importe peu (on a 1 partout)
    	{
    	   echo 'case numéro : ' . $cb . ' cochée<br />';
    	}
    	// ou 
    	$keys = array_keys( $cb_all ); // array des clés
    	asort( $keys ); // ordre croissant
    	echo 'Toutes les cases cochées sont : ' . implode( ', ', $keys );
     
    }

    N.B. une méthode plus "conventionnelle" aurait été d'attribuer le numéro à la value :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    < input ... name="cb[]" value="9" />
    (Je ne l'ai pas fait, pour ne pas avoir à trop modifier le code initial)
    Dernière modification par Invité ; 23/07/2018 à 16h51.

  9. #9
    Expert confirmé
    Avatar de Watilin
    Homme Profil pro
    En recherche d'emploi
    Inscrit en
    Juin 2010
    Messages
    3 094
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : En recherche d'emploi

    Informations forums :
    Inscription : Juin 2010
    Messages : 3 094
    Par défaut
    Citation Envoyé par giovanni Voir le message
    j'ai mis votre script sur le site tout ok sauf le envoyer ne va pas ..
    Il suffit de remettre "result.php" dans l’attribut action du formulaire.

    Citation Envoyé par giovanni
    possible d'ajouter combien de chiffre selection ?
    Je ne comprends pas cette question. Pourrais-tu reformuler ?

    Citation Envoyé par jreaux62 Voir le message
    @Watilin
    Il te manque juste le changement de couleur des cases cochées
    Oui, je ne me suis pas occupé de ça. J’ai juste fait une « traduction » de la page dans son état d’alors.

    Citation Envoyé par jreaux62
    Concernant mon code (lui aussi sans jQuery),
    Ah oui en effet, je n’ai pas été attentif… Je crois que j’ai pris les forEach pour des $.each en un coup d’œil trop rapide
    La FAQ JavaScript – Les cours JavaScript
    Touche F12 = la console → l’outil indispensable pour développer en JavaScript !

  10. #10
    Expert confirmé
    Avatar de Watilin
    Homme Profil pro
    En recherche d'emploi
    Inscrit en
    Juin 2010
    Messages
    3 094
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : En recherche d'emploi

    Informations forums :
    Inscription : Juin 2010
    Messages : 3 094
    Par défaut
    J’étais en train de poster ça avant de me rendre compte que jreaux62 m’avait devancé.

    @giovanni : ma version est légèrement différente, j’ai essayé de respecter au plus proche l’apparence de ta page, et le JS est vanilla (sans jQuery). (Edit : en fait, la version de jreaux62 est vanilla aussi )

    Code html : 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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    <!DOCTYPE html>
    <html lang="fr">
    <head>
      <meta charset="utf-8" />
      <title>Tableau page internet</title>
      <link rel="stylesheet" href="style.css" />
      <script src="script.js"></script>
    </head>
    <body>
     
    <div id="flex-container">
      <table class="flex-column">
        <tbody>
          <tr>
            <td>
              <label for="C1">1</label>
              <input type="checkbox" id="C1" name="C1" />
            </td>
            <td>
              <label for="C11">11</label>
              <input type="checkbox" id="C11" name="C11" />
            </td>
            <td>
              <label for="C21">21</label>
              <input type="checkbox" id="C21" name="C21" />
            </td>
            <td>
              <label for="C31">31</label>
              <input type="checkbox" id="C31" name="C31" />
            </td>
            <td>
              <label for="C41">41</label>
              <input type="checkbox" id="C41" name="C41" />
            </td>
            <td>
              <label for="C51">51</label>
              <input type="checkbox" id="C51" name="C51" />
            </td>
            <td>
              <label for="C61">61</label>
              <input type="checkbox" id="C61" name="C61" />
            </td>
            <td>
              <label for="C71">71</label>
              <input type="checkbox" id="C71" name="C71" />
            </td>
            <td>
              <label for="C81">81</label>
              <input type="checkbox" id="C81" name="C81" value="1" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C2">2</label>
              <input type="checkbox" id="C2" name="C2" />
            </td>
            <td>
              <label for="C12">12</label>
              <input type="checkbox" id="C12" name="C12" />
            </td>
            <td>
              <label for="C22">22</label>
              <input type="checkbox" id="C22" name="C22" />
            </td>
            <td>
              <label for="C32">32</label>
              <input type="checkbox" id="C32" name="C32" />
            </td>
            <td>
              <label for="C42">42</label>
              <input type="checkbox" id="C42" name="C42" />
            </td>
            <td>
              <label for="C52">52</label>
              <input type="checkbox" id="C52" name="C52" />
            </td>
            <td>
              <label for="C62">62</label>
              <input type="checkbox" id="C62" name="C62" />
            </td>
            <td>
              <label for="C72">72</label>
              <input type="checkbox" id="C72" name="C72" />
            </td>
            <td>
              <label for="C82">82</label>
              <input type="checkbox" id="C82" name="C82" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C3">3</label>
              <input type="checkbox" id="C3" name="C3" />
            </td>
            <td>
              <label for="C13">13</label>
              <input type="checkbox" id="C13" name="C13" />
            </td>
            <td>
              <label for="C23">23</label>
              <input type="checkbox" id="C23" name="C23" />
            </td>
            <td>
              <label for="C33">33</label>
              <input type="checkbox" id="C33" name="C33" />
            </td>
            <td>
              <label for="C43">43</label>
              <input type="checkbox" id="C43" name="C43" />
            </td>
            <td>
              <label for="C53">53</label>
              <input type="checkbox" id="C53" name="C53" />
            </td>
            <td>
              <label for="C63">63</label>
              <input type="checkbox" id="C63" name="C63" />
            </td>
            <td>
              <label for="C73">73</label>
              <input type="checkbox" id="C73" name="C73" />
            </td>
            <td>
              <label for="C83">83</label>
              <input type="checkbox" id="C83" name="C83" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C4">4</label>
              <input type="checkbox" id="C4" name="C4" />
            </td>
            <td>
              <label for="C14">14</label>
              <input type="checkbox" id="C14" name="C14" />
            </td>
            <td>
              <label for="C24">24</label>
              <input type="checkbox" id="C24" name="C24" />
            </td>
            <td>
              <label for="C34">34</label>
              <input type="checkbox" id="C34" name="C34" />
            </td>
            <td>
              <label for="C44">44</label>
              <input type="checkbox" id="C44" name="C44" />
            </td>
            <td>
              <label for="C54">54</label>
              <input type="checkbox" id="C54" name="C54" />
            </td>
            <td>
              <label for="C64">64</label>
              <input type="checkbox" id="C64" name="C64" />
            </td>
            <td>
              <label for="C74">74</label>
              <input type="checkbox" id="C74" name="C74" />
            </td>
            <td>
              <label for="C84">84</label>
              <input type="checkbox" id="C84" name="C84" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C5">5</label>
              <input type="checkbox" id="C5" name="C5" />
            </td>
            <td>
              <label for="C15">15</label>
              <input type="checkbox" id="C15" name="C15" />
            </td>
            <td>
              <label for="C25">25</label>
              <input type="checkbox" id="C25" name="C25" />
            </td>
            <td>
              <label for="C35">35</label>
              <input type="checkbox" id="C35" name="C35" />
            </td>
            <td>
              <label for="C45">45</label>
              <input type="checkbox" id="C45" name="C45" />
            </td>
            <td>
              <label for="C55">55</label>
              <input type="checkbox" id="C55" name="C55" />
            </td>
            <td>
              <label for="C65">65</label>
              <input type="checkbox" id="C65" name="C65" />
            </td>
            <td>
              <label for="C75">75</label>
              <input type="checkbox" id="C75" name="C75" />
            </td>
            <td>
              <label for="C85">85</label>
              <input type="checkbox" id="C85" name="C85" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C6">6</label>
              <input type="checkbox" id="C6" name="C6" />
            </td>
            <td>
              <label for="C16">16</label>
              <input type="checkbox" id="C16" name="C16" />
            </td>
            <td>
              <label for="C26">26</label>
              <input type="checkbox" id="C26" name="C26" />
            </td>
            <td>
              <label for="C36">36</label>
              <input type="checkbox" id="C36" name="C36" />
            </td>
            <td>
              <label for="C46">46</label>
              <input type="checkbox" id="C46" name="C46" />
            </td>
            <td>
              <label for="C56">56</label>
              <input type="checkbox" id="C56" name="C56" />
            </td>
            <td>
              <label for="C66">66</label>
              <input type="checkbox" id="C66" name="C66" />
            </td>
            <td>
              <label for="C76">76</label>
              <input type="checkbox" id="C76" name="C76" />
            </td>
            <td>
              <label for="C86">86</label>
              <input type="checkbox" id="C86" name="C86" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C7">7</label>
              <input type="checkbox" id="C7" name="C7" />
            </td>
            <td>
              <label for="C17">17</label>
              <input type="checkbox" id="C17" name="C17" />
            </td>
            <td>
              <label for="C27">27</label>
              <input type="checkbox" id="C27" name="C27" />
            </td>
            <td>
              <label for="C37">37</label>
              <input type="checkbox" id="C37" name="C37" />
            </td>
            <td>
              <label for="C47">47</label>
              <input type="checkbox" id="C47" name="C47" />
            </td>
            <td>
              <label for="C57">57</label>
              <input type="checkbox" id="C57" name="C57" />
            </td>
            <td>
              <label for="C67">67</label>
              <input type="checkbox" id="C67" name="C67" />
            </td>
            <td>
              <label for="C77">77</label>
              <input type="checkbox" id="C77" name="C77" />
            </td>
            <td>
              <label for="C87">87</label>
              <input type="checkbox" id="C87" name="C87" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C8">8</label>
              <input type="checkbox" id="C8" name="C8" />
            </td>
            <td>
              <label for="C18">18</label>
              <input type="checkbox" id="C18" name="C18" />
            </td>
            <td>
              <label for="C28">28</label>
              <input type="checkbox" id="C28" name="C28" />
            </td>
            <td>
              <label for="C38">38</label>
              <input type="checkbox" id="C38" name="C38" />
            </td>
            <td>
              <label for="C48">48</label>
              <input type="checkbox" id="C48" name="C48" />
            </td>
            <td>
              <label for="C58">58</label>
              <input type="checkbox" id="C58" name="C58" />
            </td>
            <td>
              <label for="C68">68</label>
              <input type="checkbox" id="C68" name="C68" />
            </td>
            <td>
              <label for="C78">78</label>
              <input type="checkbox" id="C78" name="C78" />
            </td>
            <td>
              <label for="C88">88</label>
              <input type="checkbox" id="C88" name="C88" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C9">9</label>
              <input type="checkbox" id="C9" name="C9" />
            </td>
            <td>
              <label for="C19">19</label>
              <input type="checkbox" id="C19" name="C19" />
            </td>
            <td>
              <label for="C29">29</label>
              <input type="checkbox" id="C29" name="C29" />
            </td>
            <td>
              <label for="C39">39</label>
              <input type="checkbox" id="C39" name="C39" />
            </td>
            <td>
              <label for="C49">49</label>
              <input type="checkbox" id="C49" name="C49" />
            </td>
            <td>
              <label for="C59">59</label>
              <input type="checkbox" id="C59" name="C59" />
            </td>
            <td>
              <label for="C69">69</label>
              <input type="checkbox" id="C69" name="C69" />
            </td>
            <td>
              <label for="C79">79</label>
              <input type="checkbox" id="C79" name="C79" />
            </td>
            <td>
              <label for="C89">89</label>
              <input type="checkbox" id="C89" name="C89" />
            </td>
          </tr>
     
          <tr>
            <td>
              <label for="C10">10</label>
              <input type="checkbox" id="C10" name="C10" />
            </td>
            <td>
              <label for="C20">20</label>
              <input type="checkbox" id="C20" name="C20" />
            </td>
            <td>
              <label for="C30">30</label>
              <input type="checkbox" id="C30" name="C30" />
            </td>
            <td>
              <label for="C40">40</label>
              <input type="checkbox" id="C40" name="C40" />
            </td>
            <td>
              <label for="C50">50</label>
              <input type="checkbox" id="C50" name="C50" />
            </td>
            <td>
              <label for="C60">60</label>
              <input type="checkbox" id="C60" name="C60" />
            </td>
            <td>
              <label for="C70">70</label>
              <input type="checkbox" id="C70" name="C70" />
            </td>
            <td>
              <label for="C80">80</label>
              <input type="checkbox" id="C80" name="C80" />
            </td>
            <td>
              <label for="C90">90</label>
              <input type="checkbox" id="C90" name="C90" />
            </td>
          </tr>
        </tbody>
      </table>
     
      <p class="flex-column">
        <a id="cleanup-button" href="#">Vider la grille</a>
      </p>
    </div><!-- #flex-container -->
     
    <form method="post" action="result.php" id="form1">
      <input type="hidden" name="validateur" value="-1" />
      <button type="submit" class="btn btn-default">Envoyer</button>
      <button type="button" id="invert-button">Invert</button>
    </form>
     
    </body>
    </html>

    Code CSS : 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
    @charset "utf-8";
     
    #flex-container {
      display: flex;
    }
     
    .flex-column {
      margin: auto;
      margin-left: 0;
      margin-right: 1em;
    }
     
    table {
      border-spacing: 0;
      text-align: right;
    }
     
    td {
      padding: 0;
      padding-left: 1ex;
    }
     
    #form1 {
      margin-top: 2em;
    }
     
    button {
      display: block;
    }

    Code JS : 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
    document.addEventListener("DOMContentLoaded", () => {
      "use strict";
     
      let cleanupButton = document.querySelector("#cleanup-button");
      let invertButton = document.querySelector("#invert-button");
      let allBoxes = document.querySelectorAll("input[type=checkbox]");
     
      function vider() {
        for (let box of allBoxes) {
          box.checked = false;
        }
      }
     
      function invertCheckboxes() {
        for (let box of allBoxes) {
          box.checked = !box.checked;
        }
      }
     
      document.addEventListener("click", (event) => {
        let target = event.target;
        if ("TD" === target.tagName) {
          let box = target.querySelector("input[type=checkbox]");
          box.checked = !box.checked;
        }
      });
     
      cleanupButton.addEventListener("click", (event) => {
        event.preventDefault();
        vider();
      });
     
      invertButton.addEventListener("click", (event) => {
        event.preventDefault();
        invertCheckboxes();
      });
    });

    Bien joué jreaux62 pour le cas légitime d’utilisation du bouton reset
    La FAQ JavaScript – Les cours JavaScript
    Touche F12 = la console → l’outil indispensable pour développer en JavaScript !

Discussions similaires

  1. Comment colorer une ligne d'un tableau avec une case à cocher ?
    Par Gdal dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 06/08/2011, 11h11
  2. [MySQL] Afficher les valeurs d'un tableau pour des cases à cocher
    Par tiesto95 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 25/12/2008, 16h45
  3. Un tableau pour chaque case à cocher
    Par The Molo dans le forum Langage
    Réponses: 3
    Dernier message: 18/08/2008, 13h49
  4. Tableau paginé + gestion cases à cocher
    Par lili2704 dans le forum Struts 1
    Réponses: 3
    Dernier message: 29/06/2007, 18h02
  5. [MySQL] Creer un formulaire avec un tableau et des cases à cocher ??
    Par shawn12 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 04/04/2006, 10h23

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