-
Notifications
You must be signed in to change notification settings - Fork 0
/
myjavascript.js
71 lines (64 loc) · 2.1 KB
/
myjavascript.js
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
function getParams(){
var name = document.getElementById("name").value
var index = document.getElementById("index").value
var phone = document.getElementById("phone").value
var ocenki = document.getElementsByName("grade")
for(let i = 0 ; i < ocenki.length ; i++){
if(ocenki[i].checked){
var grade = ocenki[i].value;
}
}
var sesija = document.getElementById("session").value
if(name == "" || index == "" || phone == "" || grade == "" || sesija == ""){
alert("Popolni gi site fields")
}else{
tabela = document.getElementById("tabela");
var tel1 = phone.slice(0,3);
var tel2 = phone.slice(3,6);
var tel3 = phone.slice(6,9);
tabela.innerHTML +=
`
<tr>
<td>${name}</td>
<td>${index}</td>
<td>${tel1}/${tel2}-${tel3}</td>
<td class="grades">${grade}</td>
<td>${sesija}</td>
<td><button onclick="confirmData(this)">Confirm</button>
<button onclick="revertData(this)">Revert</button>
</td>
</tr>
`
sum()
}
}
function sum(){
var average = document.getElementById("showAverage");
var grades = document.getElementsByClassName("grades");
var suma = 0 ;
for(let i=0;i<grades.length;i++){
suma += parseInt(grades[i].innerHTML);
}
average.innerHTML = "Average: " + suma/grades.length;
}
function confirmData(row){
tr = row.parentNode;
tr.parentNode.style.backgroundColor = "lightgreen"
row.setAttribute('disabled','true')
row.parentNode.lastElementChild.setAttribute('disabled','true')
}
function revertData(kopce){
var tr = kopce.parentNode.parentNode;
console.log(tr.childNodes)
var index = tr.childNodes[3];
var grade = tr.childNodes[7];
var lista = document.getElementById("lista");
lista.innerHTML +=
`
<li>
${index.innerHTML} - grade: ${grade.innerHTML}
</li>
`
tr.parentNode.removeChild(tr);
sum();
}