Simple Poll
How do I make an simple poll?
What is a simple poll? How do you make a simple poll? This script and codes were developed by Laura Kelly on 29 January 2023, Sunday.
Simple Poll - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple Poll</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="choices"> <div class="choice"> <div class="result"> <div class="bar" data-choice="1"></div> </div> <div class="label"> <p>Choice 1</p> <button data-choice="1">Vote</button> </div> </div> <div class="choice"> <div class="result"> <div class="bar" data-choice="2"></div> </div> <div class="label"> <p>Choice 2</p> <button data-choice="2">Vote</button> </div> </div> <div class="choice"> <div class="result"> <div class="bar" data-choice="3"></div> </div> <div class="label"> <p>Choice 3</p> <button data-choice="3">Vote</button> </div> </div>
</div> <script src="js/index.js"></script>
</body>
</html>
Simple Poll - Script Codes CSS Codes
.choice { height: 400px; display: inline-block; width: 100px;
}
.result { height: 330px; display: flex; flex-direction: column; justify-content: flex-end;
}
.bar { height: 0%; width: 70%; margin: 0 auto;
}
.bar[data-choice="1"] { background-color: red;
}
.bar[data-choice="2"] { background-color: green;
}
.bar[data-choice="3"] { background-color: blue;
}
.label { height: 70px; text-align: center;
}
Simple Poll - Script Codes JS Codes
var buttons = document.querySelectorAll(".choice button"), tally = { 1: 0, 2: 0, 3: 0, total: 0 };
function vote(choice) { tally[choice]++; tally["total"]++; console.log(tally);
}
function barPercentage(node, tally) { var choice = node.dataset.choice; if (tally[choice]) return tally[choice]/tally["total"] * 100; return 0;
}
function renderBars() { var bars = document.getElementsByClassName("bar"); for (var i = 0; i < bars.length; i++) { var percentage = barPercentage(bars[i], tally); console.log(percentage) bars[i].style.height = percentage.toString() + "%"; }
}
function setup() { // Set up event listeners for (var i = 0; i < buttons.length; i++) { buttons[i].addEventListener("click", function(e) { vote(e.target.dataset["choice"]); renderBars(); }); } renderBars();
}
setup();
Developer | Laura Kelly |
Username | laurakelly |
Uploaded | January 29, 2023 |
Rating | 3 |
Size | 2,159 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Log functions graphed with D3.js | 2,892 Kb |
Time Complexity Graphed with D3.js | 3,030 Kb |
How to make triangle SVGs | 1,472 Kb |
Plotting Points with D3.js | 31,996 Kb |
Basic split button with dropdown | 2,237 Kb |
A Pen by Laura Kelly | 2,315 Kb |
Prism Spotify | 2,216 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
BabyStore | Pablo-Ai | 3,807 Kb |
Responsive Menu I | Rodericksandoval | 3,045 Kb |
Animating characters with jQuery | 042 | 2,776 Kb |
Welcome | Nakome | 6,076 Kb |
Em Test | Rodesco | 1,784 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Amazing CSS Menu with Notification Badges | Faizanasad | 2,549 Kb |
Masonry | Uriuriuriu | 5,005 Kb |
Slick Slider | Wearebold | 5,913 Kb |
Slide In Panel | Vikvarg | 2,811 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!