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.
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;
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>
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 ?
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>
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
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 ?
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.
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)
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)
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)
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)