-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (71 loc) · 2.65 KB
/
script.js
File metadata and controls
90 lines (71 loc) · 2.65 KB
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
// #dynamic table script
// Activy listing
//===============
const activites = [
{ titre: "Patchwork", prix: 25 }, // 0
{ titre: "Peinture", prix: 35 }, // 1
{ titre: "Encadrement", prix: 22 }, // 2
{ titre: "Gymnastique", prix: 17 }, // 3
{ titre: "Photographie", prix: 45 }, // 4
{ titre: "Emaux", prix: 30 }, // 5
{ titre: "Création textile", prix: 30 }, // 6
{ titre: "Roller", prix: 58 }, // 7
{ titre: "Généalogie", prix: 15 }, // 8
{ titre: "Scrapbooking", prix: 20 }, // 9
{ titre: "Frais d'adhésions", prix: 35 } // 10
];
const euro = new Intl.NumberFormat( 'de-DE', { style: 'currency', currency: 'EUR' } );
function initTableau() {
const tbody = document.querySelector( '#table-facture' ).querySelector( 'tbody');
for ( let i = 0; i < activites.length; i++ )
{
const ligne = tbody.insertRow();
// activities cells
let cellActivite = ligne.insertCell();
cellActivite.innerHTML = activites[ i ].titre;
cellActivite.className = 'lib-acti';
// cotisations cells
let cellCotisation = ligne.insertCell();
cellCotisation.innerHTML = euro.format( activites[ i ].prix );
cellCotisation.className = 'fld-num';
// choices cells
let cellChoix = ligne.insertCell();
cellChoix.className = 'fld-log';
if ( i === activites.length -1 )
{
// last line, mandatory fee (subscription fee)
cellChoix.innerHTML = '<input type="checkbox" disabled checked />';
}
else
{
cellChoix.innerHTML = '<input type="checkbox" />';
}
// prices cells
cellTarif = ligne.insertCell();
cellTarif.innerHTML = euro.format( 0 );
cellTarif.className = 'fld-num';
}
}
// calling function initTableau
initTableau();
;
function calculCotisation(){
const tabTr = document.querySelector( '#table-facture' ).querySelector( 'tbody' ).querySelectorAll( 'tr' );
let total = 0;
for ( let i = 0; i < activites.length; i++ )
{
if ( tabTr[ i ]. cells[ 2 ].childNodes[ 0 ].checked )
{
tabTr[ i ].cells[ 3 ].innerHTML = activites[ i ].prix;
total += activites[ i ].prix;
}
else
{
tabTr[ i ].cells[ 3 ].innerHTML = 0;
}
}
document.querySelector( '#total' ).innerHTML = total;
}
// calling function calculCotisation
calculCotisation();
;