-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult.html
More file actions
69 lines (62 loc) · 2.95 KB
/
Copy pathresult.html
File metadata and controls
69 lines (62 loc) · 2.95 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voting Results</title>
<link rel="stylesheet" href="result.css">
</head>
<body>
<div class="container">
<h1>Voting Results</h1>
<!-- Voting Results Section -->
<div id="voting-results" style="display: none;">
<div id="totalVotes" class="result-item"></div>
<div id="candidateA" class="result-item"></div>
<div id="candidateB" class="result-item"></div>
<div id="candidateC" class="result-item"></div>
</div>
<!-- Message for voting not ended -->
<div id="notEndedMessage" style="display: none;">
<p>Voting has not ended yet. Please wait for the results.</p>
</div>
<!-- Refresh Button -->
<div>
<button id="refreshButton" class="btn">Refresh Results</button>
</div>
</div>
<script>
// Function to fetch and display the voting data
function fetchVotingResults() {
fetch('/votingData.json') // Fetch the voting data from the JSON file
.then(response => {
if (!response.ok) {
// If votingData.json is not found, show the message that voting hasn't ended
document.getElementById('voting-results').style.display = 'none';
document.getElementById('notEndedMessage').style.display = 'block';
return Promise.reject('Voting results not available');
}
return response.json();
})
.then(data => {
// If voting data is available, display the results
document.getElementById('totalVotes').textContent = `Total Votes: ${data.totalVotes}`;
document.getElementById('candidateA').textContent = `Candidate A: ${data.candidates.candidateA} votes`;
document.getElementById('candidateB').textContent = `Candidate B: ${data.candidates.candidateB} votes`;
document.getElementById('candidateC').textContent = `Candidate C: ${data.candidates.candidateC} votes`;
// Show the results and hide the "not ended" message
document.getElementById('voting-results').style.display = 'block';
document.getElementById('notEndedMessage').style.display = 'none';
})
.catch(error => {
// Handle errors if any
console.error("Error fetching voting data:", error);
});
}
// Call the function when the page loads
window.onload = fetchVotingResults;
// Add event listener for the refresh button
document.getElementById('refreshButton').addEventListener('click', fetchVotingResults);
</script>
</body>
</html>