-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (50 loc) · 1.13 KB
/
Copy pathscript.js
File metadata and controls
58 lines (50 loc) · 1.13 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
var element;
function showDialog(event){
document.getElementById("popUpHolder").style.visibility = "visible";
element=this.parentNode;
}
sumVotes={
"rating1":0,
"rating2":0,
"rating3":0,
"rating4":0,
"rating5":0
};
numberVotes={
"rating1":0,
"rating2":0,
"rating3":0,
"rating4":0,
"rating5":0
};
function addVote(i,value){
sumVotes[i]=parseInt(sumVotes[i]) + parseInt(value);
numberVotes[i]=numberVotes[i]+1;
console.log(numberVotes[i]);
}
function calculateRating(i){
if(numberVotes[i]!=0){
return sumVotes[i]/numberVotes[i];
}
else return "No votes, yet."
}
function updateRating(i){
id="rating" + (i+1);
console.log(id)
}
function rate(event){
value=0
var radios = document.getElementsByName('rating');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
value=radios[i].value;
break;
}
}
console.log(element);
rateElement=element.getElementsByTagName("span")[0];
console.log(rateElement.id);
addVote(rateElement.id,value);
document.getElementById("popUpHolder").style.visibility = "hidden";
rateElement.innerHTML=calculateRating(rateElement.id);
}