Here is an example of how to create a progress bar in HTML with four options that allow the user to input percentages:
<div class="progress">
<div class="bar"></div>
</div>
<form>
<label for="progress1">Option 1:</label>
<input type="number" id="progress1" min="0" max="100">
<label for="progress2">Option 2:</label>
<input type="number" id="progress2" min="0" max="100">
<label for="progress3">Option 3:</label>
<input type="number" id="progress3" min="0" max="100">
<label for="progress4">Option 4:</label>
<input type="number" id="progress4" min="0" max="100">
<button type="submit">Update Progress</button>
</form>
.progress {
background-color: #ddd;
height: 20px;
margin-bottom: 20px;
position: relative;
width: 100%;
}
.bar {
background-color: #4CAF50;
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width 0.5s ease-in-out;
width: 0;
}
const form = document.querySelector('form');
const bar = document.querySelector('.bar');
form.addEventListener('submit', function(event) {
event.preventDefault(); // prevent form from submitting
const progress1 = document.getElementById('progress1').value;
const progress2 = document.getElementById('progress2').value;
const progress3 = document.getElementById('progress3').value;
const progress4 = document.getElementById('progress4').value;
const totalProgress = Number(progress1) + Number(progress2) + Number(progress3) + Number(progress4);
const averageProgress = totalProgress / 4;
bar.style.width = `${averageProgress}%`;
});
This JavaScript code gets the values of the input fields when the form is submitted, calculates the average percentage of all the inputs, and updates the width of the bar accordingly.
Note that this is just one way to create a progress bar in HTML with input fields. There are many other methods and variations that you can use depending on your specific needs.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-08 23:06:54 +0000
Seen: 11 times
Last updated: Jul 08 '23
What is the process for generating a dynamic subdomain/URL using vue.js?
How can the style of the loader be modified while the form submission is being processed?
I'm attempting to develop a Javascript-based comments section for my website.
What are some feasible methods to enable MIDI file playback on a web browser?
How can I resolve the issue of being unable to use Fetch to POST an array of Selected Checkboxes?
What is the method to hide the scroll button when reaching the bottom?
What is the process of using a custom nunjucks filter to filter collections in an eleventy template?
What is the method to create a dynamic checkbox using API data?
How can the user id from the login object be utilized in the resolvers after logging in?