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 :

Valeur incorrecte utilisée pour l'id d'un bouton


Sujet :

JavaScript

  1. #1
    Membre éprouvé
    Avatar de beegees
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2004
    Messages
    3 610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2004
    Messages : 3 610
    Points : 1 277
    Points
    1 277
    Par défaut Valeur incorrecte utilisée pour l'id d'un bouton
    Bonjour tout le monde,

    Je reprends le code de quelqu'un pour résoudre plusieurs bugs.

    Je n'arrive pas à trouver la solution pour le dernier bug, l'id de la cotisation du membre est toujours égal à 13 :

    Dans la BD j'ai :

    Nom : Capture d'écran 2018-02-10 11.31.01.png
Affichages : 110
Taille : 35,8 Ko

    Au retour de PHP (ajax), j'ai ceci :

    [{"idCotisation":"13","montant":"10.00"},{"idCotisation":"58","montant":"10.00",{"idCotisation":"85","montant":"5.00"},{"idCotisation":"86","montant":"5.00"},{"idCotisation":"115","montant":"10.00"},{"idCotisation":"142","montant":"10.00"}
    etc...
    ]
    Le problème est le suivant, il y a création de bouton avec id, mais l'id de la cotisation est toujours 13 :

    Nom : Capture d'écran 2018-02-10 11.47.00.png
Affichages : 87
Taille : 309,0 Ko

    C'est la variable data-whatever="13" qui nous intéresse dans ce cas.

    Voici le code, j'ai pas débugué, mais je n'y arrive pas (voir ligne 176 à 178 :

    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
    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
    $.ajax(
     
             {
                type: 'POST',
                url: 'php/gestionCotisations.php',
                data: {
                         to_send:to_send
                      },
                dataType:'text',
                success:function(retour_php)
                {
                   //alert(retour_php);
                   try
                   {
                      var retour = JSON.parse(retour_php);
                      //console.log('ici 3-> '+retour);
                   }
                   catch(error)
                   {
                      $('#nombre_resultat2').text('Aucun résultat trouvé!').css("color","red");
                      $("ul.listetotale div").remove();
                      return false;
                   }
     
                   //console.warn(retour);
                   if(retour == "" || retour == false)
                   {
                      console.warn("NO DATA BACK!");
                      $('#nombre_resultat2').text('Aucun résultat trouvé!').css("color","red");
                      $("ul.listetotale div").remove();
                      return false;
                   }
     
     
                   //suppression totale des résultats
                   $("ul.listetotale div").remove();
                   //var lastval={};
                   //var rejoin;
                   var alldata="";
                   var lastId="";
                   var doublons=0;
                   var pass=0;
                   var tempval="";
                   var total = 0;
                   var totalDon = 0;
                   var totalMembre = 0;
                   var nextline=0;
                   var montant=0;
                   var num_versement=0;
                   var communication=0;
                   var type=0;
     
                   //alert(retour.length);
                   for(var i = 0; i < retour.length; i++)
                   {
                       var obj = retour[i];
                       //alert(obj[i]);
                       //console.log('llllllaaaaa --->'+obj[i]);
                       if (nextline > 1)
                       {
                          nextline-=1;
                          doublons+=1;
                          continue;
                       }
     
                       total = 0;
                       totalDon = 0;
                       totalMembre = 0;
     
                      $.each(obj, function(index, value)
                      {
     
                           if (value == null || value == undefined)
                           {
                              obj[index] = "";
                           }
                      });
     
                       if ((!($("#noNames").is(":checked")) && obj.nom=="" && obj.prenom==""))
                       {
                          continue;
                       }
                       //Trop gourmand , essai pour le gif non concluant voire pire avec d'autre animation en js.
                       //timestamp=Date();
                       //while (new Date() < timestamp +1) {};
                        alldata+= '<div><li><div class="panel panel-default"><div class="panel-heading">\
                        <h4 class="panel-title">';
     
                        //console.log('iciiiiiiiiiii -->'+ value);
     
                        if (obj.nom == "" && obj.prenom == "")
                        {
                          alldata+='<a data-toggle="collapse" href="#' + obj.idMembre + '" class="membreNomPrenom">Sans nom et prénom, institution: '+ obj.institution + '</a>';
                        }
     
                        else
                        {
                          alldata+='<a data-toggle="collapse" href="#' + obj.idMembre + '" class="membreNomPrenom">'+ obj.nom+ ' ' + obj.prenom+ '</a>';
                        }
     
                        alldata+='</h4>\
                         </div>\
                        <div id="' + obj.idMembre + '" class="panel-collapse collapse" >\
                        <div class="panel-body">\
                        <div class="container-fluid">\
                        <div class="row" style="margin-bottom: 10px">';
     
                        //création d'une cotisation
                        if (create_cot)
                        {
                            alldata+='<div class="col-md-1">\
                            <button type="button" class="btn btn-default btn-sm" aria-label="Left Align" data-target="#modalAjoutCotisation" data-whatever="' + obj.idMembre + '" data-toggle="modal" >\
                              <span class="glyphicon glyphicon-plus"></span>\
                              Ajouter une cotisation\
                            </button>\
                          </div>';
                        }
     
                        alldata+='</div>\
                        <div class="table-responsive">\
                        <table class="table">\
                        <thead>\
                        <tr>\
                        <th>Extrait</th>\
                        <th>Date</th>\
                        <th>Montant</th>\
                        <th>Communication</th>\
                        <th>Type</th>';
     
                        alldata+='</tr>\
                        </thead>\
                        <tbody id="'+obj.idMembre+'">';
     
                       nextline=0;
                       do
                       {
                        if (nextline>=1)
                        {
                          montant=retour[i+nextline].montant;
                          num_versement=retour[i+nextline].num_versement;
                          date_paiement=retour[i+nextline].date_paiement;
                          communication=retour[i+nextline].communication;
                          type=retour[i+nextline].type;
                          idcot = [i+nextline].idCotisation;
                          //alert(idcot);
                        }
                        else
                        {
                          montant = obj.montant;
                          num_versement = obj.num_versement;
                          date_paiement = obj.date_paiement;
                          communication = obj.communication;
                          type = obj.type;
                          idcot = obj.idCotisation;
                          //alert(idcot);
                        }
     
                        if (montant !=0)
                        {
                          total += parseFloat(montant);
                        }
     
                        //alert(obj.idCotisation);
                        alldata+='<tr id="'+ obj.idCotisation + '">';
                        alldata+='<td class="numVersement">ici ->' + num_versement + '</td>';
                        alldata+='<td class="datePaiement">' + date_paiement + '</td>';
                        alldata+='<td class="montantCotisation">' + montant + '</td>';
                        alldata+='<td class="communication">' + communication + '</td>';
                        alldata+='<td class="type">' + type + '</td>';
     
                        if (total>0)
                        {
                          if (up_cot)
                          {
     
                          alldata+='<th><button type="button" class="btn btn-default" aria-label="Left Align" data-target="#modalModificationPaiement" data-whatever="' + obj.idCotisation + '" data-toggle="modal" >\
                           <span  class="glyphicon glyphicon-pencil" aria-hidden="true"></span>\
                           </button></th>';
                          }
     
                          //suppressionCotisation
                          if (del_cot)
                          {
                            alldata+='<th><button type="button" class="btn btn-default" aria-label="Left Align" data-whatever="' + obj.idCotisation + '">\
                           <span  id="suppressionCotisation" class="glyphicon glyphicon-trash" aria-hidden="true"></span>\
                           </button></th>';
                          }
                        }
    Je vous remercie d'avance pour votre aide.

    bee

  2. #2
    Expert confirmé Avatar de psychadelic
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    2 529
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 2 529
    Points : 4 740
    Points
    4 740
    Par défaut
    ton attribut data-whatever est renseigné par l'élément jso =: obj.idMembre (ligne 111)

    qui semble sorti du chapeau et qu'on retrouve 3 fois (lignes 93, 98, 111, 132 )

    Quand je vois ton objet JSON :
    [{"idCotisation":"13","montant":"10.00"},{"idCotisation":"58","montant":"10.00",{"idCotisation":"85","montant":"5.00"},{"idCotisation":"86","montant":"5.00"},{"idCotisation":"115","montant":"10.00"},{"idCotisation":"142","montant":"10.00"}
    etc...
    ]
    a part des éléments idCotisation ou montant je ne vois aucun élément idMembre
    «La pluralité des voix n'est pas une preuve, pour les vérités malaisées à découvrir, tant il est bien plus vraisemblable qu'un homme seul les ait rencontrées que tout un peuple.» [ René Descartes ] - Discours de la méthode

Discussions similaires

  1. [C::B 13.12] Valeurs incorrectes affichées pour le débogage
    Par troumad dans le forum Code::Blocks
    Réponses: 0
    Dernier message: 28/11/2015, 14h59
  2. Réponses: 2
    Dernier message: 14/05/2012, 16h37
  3. [MySQL] Utilisation des valeur choix multiple pour executer une requete une valeur a la fois
    Par guigui69 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 26/12/2007, 16h43
  4. Valeur incorrecte pour ce champ (case à cocher)
    Par pifou25 dans le forum Access
    Réponses: 3
    Dernier message: 29/12/2006, 17h19
  5. Erreur : Valeur incorrecte pour ce champ
    Par Invité dans le forum Access
    Réponses: 5
    Dernier message: 04/01/2006, 12h09

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