Partage
  • Partager sur Facebook
  • Partager sur Twitter

Sous-totaux automatique...

calcul via javascript

    10 décembre 2011 à 16:50:28

    Bonjour,


    Je viens vers vous car je ne sais pas comment faire agir ma fonction qui me donne mes sous-totaux.

    En effet, si le formulaire est vierge, pas de souci, les sous-totaux fonctionne bien.

    Mais dès que je rappelle le formulaire déjà rempli avec des éléments inscrit dans ma bdd, mon formulaire affiche bien les résultats.

    Et si je modifie ces résultats, mes sous-totaux ne se mettent pas à jour comme l'image ci dessous vous l'explique.


    Image utilisateur



    function calcul_h(){
    	var hn_lundi = parseFloat(document.getElementById("hn_lundi").value);
    		if (isNaN(hn_lundi)) hn_lundi = 0;
    	var hn_mardi = parseFloat(document.getElementById("hn_mardi").value);
    		if (isNaN(hn_mardi)) hn_mardi = 0;
    .....
    document.getElementById("hn_semaine").value= hn_lundi+hn_mardi+hn_mercredi+hn_jeudi+hn_vendredi+hn_samedi+hn_dimanche;
    




    <tr>
    	<td class="col_1">Heures Normales</td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_lundi" value="<?php echo $data_personnel_heure ['hn_lundi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_mardi" value="<?php echo $data_personnel_heure ['hn_mardi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_mercredi" value="<?php echo $data_personnel_heure ['hn_mercredi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_jeudi" value="<?php echo $data_personnel_heure ['hn_jeudi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_vendredi" value="<?php echo $data_personnel_heure ['hn_vendredi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_samedi" value="<?php echo $data_personnel_heure ['hn_samedi'];?>" onblur="calcul_h()"/></td>
    	<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> name="hn_dimanche" value="<?php echo $data_personnel_heure ['hn_dimanche'];?>" onblur="calcul_h()"/></td>
    	<td class="col_3"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" id="hn_semaine" name="hn_semaine" value="<?php echo $data_personnel_heure ['hn_semaine'];?>"/></td>
    </tr>
    
    • Partager sur Facebook
    • Partager sur Twitter
      11 décembre 2011 à 10:41:01

      C'est normal, tu as mis un attribue "name" au lieu d'un attribut "id" a tes inputs, puisque tu fais document.getElementById('') ça ne fonctionne pas ^^
      • Partager sur Facebook
      • Partager sur Twitter

      Je vous ai aidé ? Appuyez sur le bouton "Ce message est utile", avec le pouce levé vers le haut !  (en bas à gauche de mon message)

        13 décembre 2011 à 19:08:50

        Citation : crf 70

        C'est normal, tu as mis un attribue "name" au lieu d'un attribut "id" a tes inputs, puisque tu fais document.getElementById('') ça ne fonctionne pas ^^




        Effectivement, mais chose étant corrigé, cela ne fonctionne pas mieux...

        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_lundi" name="hn_lundi" value="<?php echo $data_personnel_heure ['hn_lundi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_mardi" name="hn_mardi" value="<?php echo $data_personnel_heure ['hn_mardi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_mercredi" name="hn_mercredi" value="<?php echo $data_personnel_heure ['hn_mercredi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_jeudi" name="hn_jeudi" value="<?php echo $data_personnel_heure ['hn_jeudi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_vendredi" name="hn_vendredi" value="<?php echo $data_personnel_heure ['hn_vendredi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_samedi" name="hn_samedi" value="<?php echo $data_personnel_heure ['hn_samedi'];?>" onblur="calcul_h()"/></td>
        <td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_dimanche" name="hn_dimanche" value="<?php echo $data_personnel_heure ['hn_dimanche'];?>" onblur="calcul_h()"/></td>
        <td class="col_3"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" id="hn_semaine" name="hn_semaine" value="<?php echo $data_personnel_heure ['hn_semaine'];?>"/></td>
        
        • Partager sur Facebook
        • Partager sur Twitter
          13 décembre 2011 à 19:27:23

          Que dit la console d'erreur ?
          Difficile de régler un problème a l'aveugle des fois ^^

          Peut être remplacer onblur par onchange, m'enfin je ne sais pas si ça fera grand chose ^^
          • Partager sur Facebook
          • Partager sur Twitter

          Je vous ai aidé ? Appuyez sur le bouton "Ce message est utile", avec le pouce levé vers le haut !  (en bas à gauche de mon message)

            13 décembre 2011 à 19:30:30

            Comment actionner la console d'erreur ?
            • Partager sur Facebook
            • Partager sur Twitter
            Anonyme
              13 décembre 2011 à 19:37:56

              Fait un parseInt() sur tes .value pour que Javascript SACHE que c'est des NOMBRES à additionner ;)
              • Partager sur Facebook
              • Partager sur Twitter
                13 décembre 2011 à 20:05:27

                Citation : Jul1en69

                Fait un parseInt() sur tes .value pour que Javascript SACHE que c'est des NOMBRES à additionner ;)



                parseInt n'est-il pas fait que pour des entiers ?


                J'ai testé sans succès...
                • Partager sur Facebook
                • Partager sur Twitter
                  13 décembre 2011 à 20:49:48

                  En principe Ctrl+Maj+O (Opera) ou alors Ctrl+Maj+J (je crois que c'est ça sur Firefox)

                  Sinon tu vas dans outils, en cherchant un peu on trouve ;)

                  Ouvre la console, vide la, teste ton script et montre nous ce qui apparait en suite !

                  Voila un petit chapitre sur les consoles d'erreur :

                  http://www.siteduzero.com/tutoriel-3-3 [...] tml#ss_part_2
                  • Partager sur Facebook
                  • Partager sur Twitter

                  Je vous ai aidé ? Appuyez sur le bouton "Ce message est utile", avec le pouce levé vers le haut !  (en bas à gauche de mon message)

                    13 décembre 2011 à 21:01:13




                    Oups :
                    Erreur : uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIWebNavigation.loadURI]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://global/content/viewSource.js :: viewSource :: line 179" data: no]</body> </html>
                    • Partager sur Facebook
                    • Partager sur Twitter
                      14 décembre 2011 à 21:15:47

                      Un petit up car je ne m'en sort pas...

                      Je n'arrive toujours pas à afficher mon calcul dans la colonne dont l'id est hn_semaine...


                      Voilà le code javascript :
                      <script type="text/javascript"> 
                      function calcul_h(){
                      	var hn_lundi = parseFloat(document.getElementById("hn_lundi").value);
                      		if (isNaN(hn_lundi)) hn_lundi = 0;
                      	var hn_mardi = parseFloat(document.getElementById("hn_mardi").value);
                      		if (isNaN(hn_mardi)) hn_mardi = 0;
                      	var hn_mercredi = parseFloat(document.getElementById("hn_mercredi").value);
                      		if (isNaN(hn_mercredi)) hn_mercredi = 0;
                      	var hn_jeudi = parseFloat(document.getElementById("hn_jeudi").value);
                      		if (isNaN(hn_jeudi)) hn_jeudi = 0;
                      	var hn_vendredi = parseFloat(document.getElementById("hn_vendredi").value);
                      		if (isNaN(hn_vendredi)) hn_vendredi = 0;
                      	var hn_samedi = parseFloat(document.getElementById("hn_samedi").value);
                      		if (isNaN(hn_samedi)) hn_samedi = 0;
                      	var hn_dimanche = parseFloat(document.getElementById("hn_dimanche").value);
                      		if (isNaN(hn_dimanche)) hn_dimanche = 0;
                      							
                      document.getElementById("hn_semaine").value= hn_lundi+hn_mardi+hn_mercredi+hn_jeudi+hn_vendredi+hn_samedi+hn_dimanche;
                      }
                      </script>
                      



                      Et ma page php :
                      <td><input type="text" id="hn_lundi" name="hn_lundi" value="<?php echo $data_personnel_heure ['hn_lundi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_mardi" name="hn_mardi" value="<?php echo $data_personnel_heure ['hn_mardi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_mercredi" name="hn_mercredi" value="<?php echo $data_personnel_heure ['hn_mercredi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_jeudi" name="hn_jeudi" value="<?php echo $data_personnel_heure ['hn_jeudi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_vendredi" name="hn_vendredi" value="<?php echo $data_personnel_heure ['hn_vendredi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_samedi" name="hn_samedi" value="<?php echo $data_personnel_heure ['hn_samedi'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_dimanche" name="hn_dimanche" value="<?php echo $data_personnel_heure ['hn_dimanche'];?>" onblur="calcul_h()"/></td>
                      <td><input type="text" id="hn_semaine" name="hn_semaine" value="<?php echo $data_personnel_heure ['hn_semaine'];?>"/></td>
                      
                      • Partager sur Facebook
                      • Partager sur Twitter
                        14 décembre 2011 à 21:23:24

                        Je viens de tester le code que tu as mis et il fonctionne bien.
                        Ne serait-ce pas parce que répètes plusieurs fois de suite le même code pour toutes tes lignes ?
                        • Partager sur Facebook
                        • Partager sur Twitter
                          14 décembre 2011 à 21:45:09

                          Ce code est un bout de code. je l'ai simplifié pour ne pas trop noyer mes lecteurs.

                          Le voilà au complet :


                          <script type="text/javascript"> 
                          					function calcul_h(){
                          					 	var hn_lundi = parseFloat(document.getElementById("hn_lundi").value);
                          							if (isNaN(hn_lundi)) hn_lundi = 0;
                          						var hn_mardi = parseFloat(document.getElementById("hn_mardi").value);
                          							if (isNaN(hn_mardi)) hn_mardi = 0;
                          						var hn_mercredi = parseFloat(document.getElementById("hn_mercredi").value);
                          							if (isNaN(hn_mercredi)) hn_mercredi = 0;
                          						var hn_jeudi = parseFloat(document.getElementById("hn_jeudi").value);
                          							if (isNaN(hn_jeudi)) hn_jeudi = 0;
                          						var hn_vendredi = parseFloat(document.getElementById("hn_vendredi").value);
                          							if (isNaN(hn_vendredi)) hn_vendredi = 0;
                          						var hn_samedi = parseFloat(document.getElementById("hn_samedi").value);
                          							if (isNaN(hn_samedi)) hn_samedi = 0;
                          						var hn_dimanche = parseFloat(document.getElementById("hn_dimanche").value);
                          							if (isNaN(hn_dimanche)) hn_dimanche = 0;
                          						
                          						var hm100_lundi = parseFloat(document.getElementById("hm100_lundi").value);
                          							if (isNaN(hm100_lundi)) hm100_lundi = 0;
                          						var hm100_mardi = parseFloat(document.getElementById("hm100_mardi").value);
                          							if (isNaN(hm100_mardi)) hm100_mardi = 0;
                          						var hm100_mercredi = parseFloat(document.getElementById("hm100_mercredi").value);
                          							if (isNaN(hm100_mercredi)) hm100_mercredi = 0;
                          						var hm100_jeudi = parseFloat(document.getElementById("hm100_jeudi").value);
                          							if (isNaN(hm100_jeudi)) hm100_jeudi = 0;
                          						var hm100_vendredi = parseFloat(document.getElementById("hm100_vendredi").value);
                          							if (isNaN(hm100_vendredi)) hm100_vendredi = 0;
                          						var hm100_samedi = parseFloat(document.getElementById("hm100_samedi").value);
                          							if (isNaN(hm100_samedi)) hm100_samedi = 0;
                          						var hm100_dimanche = parseFloat(document.getElementById("hm100_dimanche").value);
                          							if (isNaN(hm100_dimanche)) hm100_dimanche = 0;
                          						
                          						var hm50_lundi = parseFloat(document.getElementById("hm50_lundi").value);
                          							if (isNaN(hm50_lundi)) hm50_lundi = 0;
                          						var hm50_mardi = parseFloat(document.getElementById("hm50_mardi").value);
                          							if (isNaN(hm50_mardi)) hm50_mardi = 0;
                          						var hm50_mercredi = parseFloat(document.getElementById("hm50_mercredi").value);
                          							if (isNaN(hm50_mercredi)) hm50_mercredi = 0;
                          						var hm50_jeudi = parseFloat(document.getElementById("hm50_jeudi").value);
                          							if (isNaN(hm50_jeudi)) hm50_jeudi = 0;
                          						var hm50_vendredi = parseFloat(document.getElementById("hm50_vendredi").value);
                          							if (isNaN(hm50_vendredi)) hm50_vendredi = 0;
                          						var hm50_samedi = parseFloat(document.getElementById("hm50_samedi").value);
                          							if (isNaN(hm50_samedi)) hm50_samedi = 0;
                          						var hm50_dimanche = parseFloat(document.getElementById("hm50_dimanche").value);
                          							if (isNaN(hm50_dimanche)) hm50_dimanche = 0;
                          						
                          						var hm25_lundi = parseFloat(document.getElementById("hm25_lundi").value);
                          							if (isNaN(hm25_lundi)) hm25_lundi = 0;
                          						var hm25_mardi = parseFloat(document.getElementById("hm25_mardi").value);
                          							if (isNaN(hm25_mardi)) hm25_mardi = 0;
                          						var hm25_mercredi = parseFloat(document.getElementById("hm25_mercredi").value);
                          							if (isNaN(hm25_mercredi)) hm25_mercredi = 0;
                          						var hm25_jeudi = parseFloat(document.getElementById("hm25_jeudi").value);
                          							if (isNaN(hm25_jeudi)) hm25_jeudi = 0;
                          						var hm25_vendredi = parseFloat(document.getElementById("hm25_vendredi").value);
                          							if (isNaN(hm25_vendredi)) hm25_vendredi = 0;
                          						var hm25_samedi = parseFloat(document.getElementById("hm25_samedi").value);
                          							if (isNaN(hm25_samedi)) hm25_samedi = 0;
                          						var hm25_dimanche = parseFloat(document.getElementById("hm25_dimanche").value);
                          							if (isNaN(hm25_dimanche)) hm25_dimanche = 0;
                          						
                          						var hint_lundi = parseFloat(document.getElementById("hint_lundi").value);
                          							if (isNaN(hint_lundi)) hint_lundi = 0;
                          						var hint_mardi = parseFloat(document.getElementById("hint_mardi").value);
                          							if (isNaN(hint_mardi)) hint_mardi = 0;
                          						var hint_mercredi = parseFloat(document.getElementById("hint_mercredi").value);
                          							if (isNaN(hint_mercredi)) hint_mercredi = 0;
                          						var hint_jeudi = parseFloat(document.getElementById("hint_jeudi").value);
                          							if (isNaN(hint_jeudi)) hint_jeudi = 0;
                          						var hint_vendredi = parseFloat(document.getElementById("hint_vendredi").value);
                          							if (isNaN(hint_vendredi)) hint_vendredi = 0;
                          						var hint_samedi = parseFloat(document.getElementById("hint_samedi").value);
                          							if (isNaN(hint_samedi)) hint_samedi = 0;
                          						var hint_dimanche = parseFloat(document.getElementById("hint_dimanche").value);
                          							if (isNaN(hint_dimanche)) hint_dimanche = 0;
                          						
                          
                          						var hd_lundi = parseFloat(document.getElementById("hd_lundi").value);
                          							if (isNaN(hd_lundi)) hd_lundi = 0;
                          						var hd_mardi = parseFloat(document.getElementById("hd_mardi").value);
                          							if (isNaN(hd_mardi)) hd_mardi = 0;
                          						var hd_mercredi = parseFloat(document.getElementById("hd_mercredi").value);
                          							if (isNaN(hd_mercredi)) hd_mercredi = 0;
                          						var hd_jeudi = parseFloat(document.getElementById("hd_jeudi").value);
                          							if (isNaN(hd_jeudi)) hd_jeudi = 0;
                          						var hd_vendredi = parseFloat(document.getElementById("hd_vendredi").value);
                          							if (isNaN(hd_vendredi)) hd_vendredi = 0;
                          						var hd_samedi = parseFloat(document.getElementById("hd_samedi").value);
                          							if (isNaN(hd_samedi)) hd_samedi = 0;
                          						var hd_dimanche = parseFloat(document.getElementById("hd_dimanche").value);
                          							if (isNaN(hd_dimanche)) hd_dimanche = 0;
                          						
                          						var hf_lundi = parseFloat(document.getElementById("hf_lundi").value);
                          							if (isNaN(hf_lundi)) hf_lundi = 0;
                          						var hf_mardi = parseFloat(document.getElementById("hf_mardi").value);
                          							if (isNaN(hf_mardi)) hf_mardi = 0;
                          						var hf_mercredi = parseFloat(document.getElementById("hf_mercredi").value);
                          							if (isNaN(hf_mercredi)) hf_mercredi = 0;
                          						var hf_jeudi = parseFloat(document.getElementById("hf_jeudi").value);
                          							if (isNaN(hf_jeudi)) hf_jeudi = 0;
                          						var hf_vendredi = parseFloat(document.getElementById("hf_vendredi").value);
                          							if (isNaN(hf_vendredi)) hf_vendredi = 0;
                          						var hf_samedi = parseFloat(document.getElementById("hf_samedi").value);
                          							if (isNaN(hf_samedi)) hf_samedi = 0;
                          						var hf_dimanche = parseFloat(document.getElementById("hf_dimanche").value);
                          							if (isNaN(hf_dimanche)) hf_dimanche = 0;
                          						
                          						var hr_lundi = parseFloat(document.getElementById("hr_lundi").value);
                          							if (isNaN(hr_lundi)) hr_lundi = 0;
                          						var hr_mardi = parseFloat(document.getElementById("hr_mardi").value);
                          							if (isNaN(hr_mardi)) hr_mardi = 0;
                          						var hr_mercredi = parseFloat(document.getElementById("hr_mercredi").value);
                          							if (isNaN(hr_mercredi)) hr_mercredi = 0;
                          						var hr_jeudi = parseFloat(document.getElementById("hr_jeudi").value);
                          							if (isNaN(hr_jeudi)) hr_jeudi = 0;
                          						var hr_vendredi = parseFloat(document.getElementById("hr_vendredi").value);
                          							if (isNaN(hr_vendredi)) hr_vendredi = 0;
                          						var hr_samedi = parseFloat(document.getElementById("hr_samedi").value);
                          							if (isNaN(hr_samedi)) hr_samedi = 0;
                          						var hr_dimanche = parseFloat(document.getElementById("hr_dimanche").value);
                          							if (isNaN(hr_dimanche)) hr_dimanche = 0;
                          						
                          						var hm_lundi = parseFloat(document.getElementById("hm_lundi").value);
                          							if (isNaN(hm_lundi)) hm_lundi = 0;
                          						var hm_mardi = parseFloat(document.getElementById("hm_mardi").value);
                          							if (isNaN(hm_mardi)) hm_mardi = 0;
                          						var hm_mercredi = parseFloat(document.getElementById("hm_mercredi").value);
                          							if (isNaN(hm_mercredi)) hm_mercredi = 0;
                          						var hm_jeudi = parseFloat(document.getElementById("hm_jeudi").value);
                          							if (isNaN(hm_jeudi)) hm_jeudi = 0;
                          						var hm_vendredi = parseFloat(document.getElementById("hm_vendredi").value);
                          							if (isNaN(hm_vendredi)) hm_vendredi = 0;
                          						var hm_samedi = parseFloat(document.getElementById("hm_samedi").value);
                          							if (isNaN(hm_samedi)) hm_samedi = 0;
                          						var hm_dimanche = parseFloat(document.getElementById("hm_dimanche").value);
                          							if (isNaN(hm_dimanche)) hm_dimanche = 0;
                          						
                          						var hat_lundi = parseFloat(document.getElementById("hat_lundi").value);
                          							if (isNaN(hat_lundi)) hat_lundi = 0;
                          						var hat_mardi = parseFloat(document.getElementById("hat_mardi").value);
                          							if (isNaN(hat_mardi)) hat_mardi = 0;
                          						var hat_mercredi = parseFloat(document.getElementById("hat_mercredi").value);
                          							if (isNaN(hat_mercredi)) hat_mercredi = 0;
                          						var hat_jeudi = parseFloat(document.getElementById("hat_jeudi").value);
                          							if (isNaN(hat_jeudi)) hat_jeudi = 0;
                          						var hat_vendredi = parseFloat(document.getElementById("hat_vendredi").value);
                          							if (isNaN(hat_vendredi)) hat_vendredi = 0;
                          						var hat_samedi = parseFloat(document.getElementById("hat_samedi").value);
                          							if (isNaN(hat_samedi)) hat_samedi = 0;
                          						var hat_dimanche = parseFloat(document.getElementById("hat_dimanche").value);
                          							if (isNaN(hat_dimanche)) hat_dimanche = 0;
                          							
                          						var hcp_lundi = parseFloat(document.getElementById("hcp_lundi").value);
                          							if (isNaN(hcp_lundi)) hcp_lundi = 0;
                          						var hcp_mardi = parseFloat(document.getElementById("hcp_mardi").value);
                          							if (isNaN(hcp_mardi)) hcp_mardi = 0;
                          						var hcp_mercredi = parseFloat(document.getElementById("hcp_mercredi").value);
                          							if (isNaN(hcp_mercredi)) hcp_mercredi = 0;
                          						var hcp_jeudi = parseFloat(document.getElementById("hcp_jeudi").value);
                          							if (isNaN(hcp_jeudi)) hcp_jeudi = 0;
                          						var hcp_vendredi = parseFloat(document.getElementById("hcp_vendredi").value);
                          							if (isNaN(hcp_vendredi)) hcp_vendredi = 0;
                          						var hcp_samedi = parseFloat(document.getElementById("hcp_samedi").value);
                          							if (isNaN(hcp_samedi)) hcp_samedi = 0;
                          						var hcp_dimanche = parseFloat(document.getElementById("hcp_dimanche").value);
                          							if (isNaN(hcp_dimanche)) hcp_dimanche = 0;
                          							
                          						var hrtt_lundi = parseFloat(document.getElementById("hrtt_lundi").value);
                          							if (isNaN(hrtt_lundi)) hrtt_lundi = 0;
                          						var hrtt_mardi = parseFloat(document.getElementById("hrtt_mardi").value);
                          							if (isNaN(hrtt_mardi)) hrtt_mardi = 0;
                          						var hrtt_mercredi = parseFloat(document.getElementById("hrtt_mercredi").value);
                          							if (isNaN(hrtt_mercredi)) hrtt_mercredi = 0;
                          						var hrtt_jeudi = parseFloat(document.getElementById("hrtt_jeudi").value);
                          							if (isNaN(hrtt_jeudi)) hrtt_jeudi = 0;
                          						var hrtt_vendredi = parseFloat(document.getElementById("hrtt_vendredi").value);
                          							if (isNaN(hrtt_vendredi)) hrtt_vendredi = 0;
                          						var hrtt_samedi = parseFloat(document.getElementById("hrtt_samedi").value);
                          							if (isNaN(hrtt_samedi)) hrtt_samedi = 0;
                          						var hrtt_dimanche = parseFloat(document.getElementById("hrtt_dimanche").value);
                          							if (isNaN(hrtt_dimanche)) hrtt_dimanche = 0;
                          						
                          						var htrj_lundi = parseFloat(document.getElementById("htrj_lundi").value);
                          							if (isNaN(htrj_lundi)) htrj_lundi = 0;
                          						var htrj_mardi = parseFloat(document.getElementById("htrj_mardi").value);
                          							if (isNaN(htrj_mardi)) htrj_mardi = 0;
                          						var htrj_mercredi = parseFloat(document.getElementById("htrj_mercredi").value);
                          							if (isNaN(htrj_mercredi)) htrj_mercredi = 0;
                          						var htrj_jeudi = parseFloat(document.getElementById("htrj_jeudi").value);
                          							if (isNaN(htrj_jeudi)) htrj_jeudi = 0;
                          						var htrj_vendredi = parseFloat(document.getElementById("htrj_vendredi").value);
                          							if (isNaN(htrj_vendredi)) htrj_vendredi = 0;
                          						var htrj_samedi = parseFloat(document.getElementById("htrj_samedi").value);
                          							if (isNaN(htrj_samedi)) htrj_samedi = 0;
                          						var htrj_dimanche = parseFloat(document.getElementById("htrj_dimanche").value);
                          							if (isNaN(htrj_dimanche)) htrj_dimanche = 0;
                          							
                          						var hrou_lundi = parseFloat(document.getElementById("hrou_lundi").value);
                          							if (isNaN(hrou_lundi)) hrou_lundi = 0;
                          						var hrou_mardi = parseFloat(document.getElementById("hrou_mardi").value);
                          							if (isNaN(hrou_mardi)) hrou_mardi = 0;
                          						var hrou_mercredi = parseFloat(document.getElementById("hrou_mercredi").value);
                          							if (isNaN(hrou_mercredi)) hrou_mercredi = 0;
                          						var hrou_jeudi = parseFloat(document.getElementById("hrou_jeudi").value);
                          							if (isNaN(hrou_jeudi)) hrou_jeudi = 0;
                          						var hrou_vendredi = parseFloat(document.getElementById("hrou_vendredi").value);
                          							if (isNaN(hrou_vendredi)) hrou_vendredi = 0;
                          						var hrou_samedi = parseFloat(document.getElementById("hrou_samedi").value);
                          							if (isNaN(hrou_samedi)) hrou_samedi = 0;
                          						var hrou_dimanche = parseFloat(document.getElementById("hrou_dimanche").value);
                          							if (isNaN(hrou_dimanche)) hrou_dimanche = 0;
                          							
                          						document.getElementById("hn_semaine").value= hn_lundi+hn_mardi+hn_mercredi+hn_jeudi+hn_vendredi+hn_samedi+hn_dimanche;
                          						document.getElementById("hm100_semaine").value= hm100_lundi+hm100_mardi+hm100_mercredi+hm100_jeudi+hm100_vendredi+hm100_samedi+hm100_dimanche;
                          						document.getElementById("hm50_semaine").value= hm50_lundi+hm50_mardi+hm50_mercredi+hm50_jeudi+hm50_vendredi+hm50_samedi+hm50_dimanche;
                          						document.getElementById("hm25_semaine").value= hm25_lundi+hm25_mardi+hm25_mercredi+hm25_jeudi+hm25_vendredi+hm25_samedi+hm25_dimanche;
                          						document.getElementById("h_lundi").value= hn_lundi+hm100_lundi+hm50_lundi+hm25_lundi;
                          						document.getElementById("h_mardi").value= hn_mardi+hm100_mardi+hm50_mardi+hm25_mardi;
                          						document.getElementById("h_mercredi").value= hn_mercredi+hm100_mercredi+hm50_mercredi+hm25_mercredi;
                          						document.getElementById("h_jeudi").value= hn_jeudi+hm100_jeudi+hm50_jeudi+hm25_jeudi;
                          						document.getElementById("h_vendredi").value= hn_vendredi+hm100_vendredi+hm50_vendredi+hm25_vendredi;
                          						document.getElementById("h_samedi").value= hn_samedi+hm100_samedi+hm50_samedi+hm25_samedi;
                          						document.getElementById("h_dimanche").value= hn_dimanche+hm100_dimanche+hm50_dimanche+hm25_dimanche;
                          						document.getElementById("h_semaine").value= hn_lundi+hn_mardi+hn_mercredi+hn_jeudi+hn_vendredi+hn_samedi+hn_dimanche+hm100_lundi+hm100_mardi+hm100_mercredi+hm100_jeudi+hm100_vendredi+hm100_samedi+hm100_dimanche+hm50_lundi+hm50_mardi+hm50_mercredi+hm50_jeudi+hm50_vendredi+hm50_samedi+hm50_dimanche+hm25_lundi+hm25_mardi+hm25_mercredi+hm25_jeudi+hm25_vendredi+hm25_samedi+hm25_dimanche;
                          						document.getElementById("hint_semaine").value= hint_lundi+hint_mardi+hint_mercredi+hint_jeudi+hint_vendredi+hint_samedi+hint_dimanche;
                          						document.getElementById("hd_semaine").value= hd_lundi+hd_mardi+hd_mercredi+hd_jeudi+hd_vendredi+hd_samedi+hd_dimanche;
                          						document.getElementById("hf_semaine").value= hf_lundi+hf_mardi+hf_mercredi+hf_jeudi+hf_vendredi+hf_samedi+hf_dimanche;
                          						document.getElementById("hr_semaine").value= hr_lundi+hr_mardi+hr_mercredi+hr_jeudi+hr_vendredi+hr_samedi+hr_dimanche;
                          						document.getElementById("hm_semaine").value= hm_lundi+hm_mardi+hm_mercredi+hm_jeudi+hm_vendredi+hm_samedi+hm_dimanche;
                          						document.getElementById("hat_semaine").value= hat_lundi+hat_mardi+hat_mercredi+hat_jeudi+hat_vendredi+hat_samedi+hat_dimanche;
                          						document.getElementById("hcp_semaine").value= hcp_lundi+hcp_mardi+hcp_mercredi+hcp_jeudi+hcp_vendredi+hcp_samedi+hcp_dimanche;
                          						document.getElementById("hrtt_semaine").value= hrtt_lundi+hrtt_mardi+hrtt_mercredi+hrtt_jeudi+hrtt_vendredi+hrtt_samedi+hrtt_dimanche;
                          						document.getElementById("htrj_semaine").value= htrj_lundi+htrj_mardi+htrj_mercredi+htrj_jeudi+htrj_vendredi+htrj_samedi+htrj_dimanche;
                          						document.getElementById("hrou_semaine").value= hrou_lundi+hrou_mardi+hrou_mercredi+hrou_jeudi+hrou_vendredi+hrou_samedi+hrou_dimanche;
                          					}
                              				</script>
                          



                          Et mon PHP :
                          <tr>
                          						<td class="col_1">Heures Normales</td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_lundi" name="hn_lundi" value="<?php echo $data_personnel_heure ['hn_lundi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_mardi" name="hn_mardi" value="<?php echo $data_personnel_heure ['hn_mardi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_mercredi" name="hn_mercredi" value="<?php echo $data_personnel_heure ['hn_mercredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_jeudi" name="hn_jeudi" value="<?php echo $data_personnel_heure ['hn_jeudi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_vendredi" name="hn_vendredi" value="<?php echo $data_personnel_heure ['hn_vendredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_samedi" name="hn_samedi" value="<?php echo $data_personnel_heure ['hn_samedi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" <?php echo $var;?> id="hn_dimanche" name="hn_dimanche" value="<?php echo $data_personnel_heure ['hn_dimanche'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_3"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" id="hn_semaine" name="hn_semaine" value="<?php echo $data_personnel_heure ['hn_semaine'];?>"/></td>
                          					</tr>
                          					<tr>
                          						<td class="col_1">Heures Majorées 100%</td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_lundi" name="hm100_lundi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_lundi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_lundi" name="hm100_lundi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_mardi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_mercredi" name="hm100_mercredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_mercredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_jeudi" name="hm100_jeudi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_jeudi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_vendredi" name="hm100_vendredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_vendredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_samedi" name="hm100_samedi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_samedi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm100_dimanche" name="hm100_dimanche" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm100_dimanche'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_3"><input type="text" readonly="readonly" class="case_heure" readonly="readonly" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" name="hm100_semaine" id="hm100_semaine" value="<?php echo $data_personnel_heure ['hm100_semaine'];?>"/></td>
                          					</tr>
                          					<tr>
                          						<td class="col_1">Heures Majorées 50%</td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_lundi" name="hm50_lundi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_lundi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_mardi" name="hm50_mardi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_mardi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_mercredi" name="hm50_mercredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_mercredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_jeudi" name="hm50_jeudi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_jeudi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_vendredi" name="hm50_vendredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_vendredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_samedi" name="hm50_samedi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_samedi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm50_dimanche" name="hm50_dimanche" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_dimanche'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_3"><input type="text" readonly="readonly" class="case_heure" readonly="readonly" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" name="hm50_semaine" id="hm50_semaine" value="<?php echo $data_personnel_heure ['hm50_semaine'];?>"/></td>
                          					</tr>
                          					<tr>
                          						<td class="col_1">Heures Majorées 25%</td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_lundi" name="hm25_lundi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm50_lundi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_mardi" name="hm25_mardi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_mardi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_mercredi" name="hm25_mercredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_mercredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_jeudi" name="hm25_jeudi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_jeudi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_vendredi" name="hm25_vendredi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_vendredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_samedi" name="hm25_samedi" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_samedi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" class="case_heure" id="hm25_dimanche" name="hm25_dimanche" <?php echo $var;?> value="<?php echo $data_personnel_heure ['hm25_dimanche'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_3"><input type="text" readonly="readonly" class="case_heure" readonly="readonly" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" name="hm25_semaine" id="hm25_semaine" value="<?php echo $data_personnel_heure ['hm25_semaine'];?>"/></td>
                          					</tr>
                          					<tr>
                          						<td class="col_1">Heures Totales</td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_lundi" id="h_lundi" value="<?php echo $data_personnel_heure ['h_lundi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_mardi" id="h_mardi" value="<?php echo $data_personnel_heure ['h_mardi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_mercredi" id="h_mercredi" value="<?php echo $data_personnel_heure ['h_mercredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_jeudi" id="h_jeudi" value="<?php echo $data_personnel_heure ['h_jeudi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_vendredi" id="h_vendredi" value="<?php echo $data_personnel_heure ['h_vendredi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_samedi" id="h_samedi" value="<?php echo $data_personnel_heure ['h_samedi'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_2"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,0.4) ; font-weight:bold;" name="h_dimanche" id="h_dimanche" value="<?php echo $data_personnel_heure ['h_dimanche'];?>" onblur="calcul_h()"/></td>
                          						<td class="col_3"><input type="text" readonly="readonly" class="case_heure" style="background-color: rgba(204,153,153,1) ; font-weight:bold;" name="h_semaine" id="h_semaine" value="<?php echo $data_personnel_heure ['h_semaine'];?>" onblur="calcul_h()"/></td>
                          					</tr>
                          



                          Que veux tu dire par :

                          Citation : Claros

                          Ne serait-ce pas parce que répètes plusieurs fois de suite le même code pour toutes tes lignes ?

                          • Partager sur Facebook
                          • Partager sur Twitter
                            15 décembre 2011 à 11:21:37

                            Oula, c'est beaucoup trop long et répétitif !
                            Facilite toi la vie, raccourcis le code.

                            Tu utilises tout le temps la même forme pour récupérer la valeur et la tester, par exemple :
                            var hn_lundi = parseFloat(document.getElementById("hn_lundi").value);
                            	if (isNaN(hn_lundi)) hn_lundi = 0;
                            


                            Rien qu'avec ça, ton code est moins agréable a lire, passe par une fonction :
                            function getNumValue(an_id)	{
                            	this.day = parseFloat(document.getElementById(an_id).value);
                            		if (isNaN(this.day)) { this.day = 0; };
                            	return this.day;
                            }
                            var hn_lundi = getNumValue("hn_lundi");
                            var hn_mardi = getNumValue("hn_mardi");
                            var hn_mercredi = getNumValue("hn_mercredi");
                            var hn_jeudi = getNumValue("hn_jeudi");
                            var hn_vendredi = getNumValue("hn_vendredi");
                            var hn_samedi = getNumValue("hn_samedi");
                            var hn_dimanche = getNumValue("hn_dimanche");
                            


                            C'est tout de suite plus court non ?
                            ensuite a la fin, tu fais plusieurs fois
                            document.getElementById("hn_semaine").value = ......;
                            


                            Passe encore par une fonction ;)
                            function getIdValue(an_id)	{
                            	return document.getElementById(an_id).value;
                            }
                            getIdValue("hn_semaine") = .....;
                            getIdValue("hm100_semaine") = .....;
                            


                            Ensuite, tu utilises toujours le nom + le jour pour les noms de tes variables, pourquoi ne pas en faire un tableau ?
                            Puisqu'il y a 7 jours, c'est assez simple :
                            function getNumValue(an_id)	{
                            	this.day = parseFloat(document.getElementById(an_id).value);
                            		if (isNaN(this.day)) { this.day = 0; };
                            	return this.day;
                            }
                            var hn = [];
                            var hn[0] = getNumValue("hn_lundi");
                            var hn[1] = getNumValue("hn_mardi");
                            var hn[2] = getNumValue("hn_mercredi");
                            var hn[3] = getNumValue("hn_jeudi");
                            var hn[4] = getNumValue("hn_vendredi");
                            var hn[5] = getNumValue("hn_samedi");
                            var hn[6] = getNumValue("hn_dimanche");
                            


                            Ce n'est que des conseils, mais c'est parfois pratique, applique les ou non c'est ton choix, peut être qu'après on trouvera plus facilement le problème ?
                            • Partager sur Facebook
                            • Partager sur Twitter

                            Je vous ai aidé ? Appuyez sur le bouton "Ce message est utile", avec le pouce levé vers le haut !  (en bas à gauche de mon message)

                            Sous-totaux automatique...

                            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                            • Editeur
                            • Markdown