Tips for adjusting the progress bar to 100% and back to 0%

My goal is to increase the progress bar percentage with each click. Currently, it only goes up to 75%. When saving, it should show 100%, but it's not displaying that properly. On clicking the back button, it should reset to 0% on the third click.

HTML

<div id="myProgressbar" class="progress" style="height: 2px;">
    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%; height: 10px;">
        <span class="sr-only">0% Complete</span>
    </div>
</div>
<div class="btns">
    <button type="button" name="sub" id="back" class="btn btn-default btn-lg" onclick="myFunctions()">back</button>
    <button type="button" name="add" id="continue" class="btn btn-success btn-lg" onclick="myFunction()" >Continue</button>
</div>

...

Javascript

<script>
    var num = 1;
        document.getElementById("back").disabled = true;
        document.getElementById("details").style.display="none";
        document.getElementById("person").style.display="block";
        document.getElementById("account").style.display="none";
        document.getElementById("premium").style.display="none";

    function myFunction() {
        var listArry = document.getElementsByClassName('list');
        for(var i = 0; i < listArry.length; i++){
            listArry[i].style.color = "#CCC";
        }

        if (num==1){
            ...
            num=2;
        }
        
        else if(num==2){
            ...
            num=3;
        }

        else if(num==3){
            ...
        }
    }
</script>

...

Answer ā„–1

Hello, I have come up with a solution to meet your requirement. Please give it a try and provide us with feedback.

var width = 40;
function move(data) {
  var elem = document.getElementById("myBar");   
if(data == 'back' && width != 0){
    width = width-10; 
      elem.style.width = width + '%';
    }else if(data == 'continue' && width != 100){
    width = width+10; 
      elem.style.width = width + '%';
      
    }  
}
<!DOCTYPE html>
<html>
<style>
#myProgress {
  width: 100%;
  background-color: #ddd;
}

#myBar {
  width: 40%;
  height: 30px;
  background-color: #4CAF50;
}
</style>
<body>

<h1>JavaScript Progress Bar</h1>

<div id="myProgress">
  <div id="myBar"></div>
</div>

<br>
<button onclick="move('back')">Back</button>
<button onclick="move('continue')">Continue</button>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for declaring a member variable as an extended type in TypeScript?

Is it possible to declare a "member variable" as an "extension object" rather than a static type (without relying on an interface)? Imagine something like this pseudocode: class Foo { bar -> extends Rectangle; constructor(barInstance:IRec ...

I am unable to incorporate additional HTML files, resulting in the header not being displayed

<html> <?require('header.html');?> <!-- page content --> <p>Welcome to the headquarters of A1 Consulting. Take a moment to familiarize yourself with our services.</p> <p>We specialize i ...

Guide on adding HTML to a specific div element in jQuery by utilizing the keyword "(this)"

I have been working on a script for my PHP page in Wordpress to add titles to images in my photo gallery that open in a lightbox. Here's what I developed: $(".responsive1").bind("click", function() { $(this).("<div class='imgTitle ...

Updating the Hero Image

Scenario: In my project directory, under Product -> src -> static -> ostatic [ there are two folders named css and images ] -> images -> where all the images can be found. I am using bootstrap and attempting to set a background-image for j ...

To show the image along with the .titleclass, .subtitleclass, and .description when clicking on it, what steps do I

<?php while($galleryrec = mysqli_fetch_array($getresultgallery)){ ?> <div class="col-lg-2 col-md-2 mb-4 mb-lg-0" id="imageidback"> <img data-id ="<?php echo $galleryrec['publishid& ...

Creating a vertical navigation menu and displaying its submenu on corresponding pages in a horizontal layout

I'm struggling to design a navigation layout for my website where I want to display the main menu items like this: Menu 1 Menu 2 Menu 3 Menu 4 Menu 5 and have their respective sub-menus displayed horizontally on their main menu pages like this: ...

Repeatedly triggering the Jquery Dialog Event

When I open a calendar plugin in jquery dialog, I encounter a recurring issue. Every time I close and reopen the dialog, my calendar event onDayClick triggers multiple times ā€“ twice, thrice, and so on. <div id="show_calendar"> <div class="c ...

Troubleshooting Display Problems when Switching Bootstrap Themes in ASP.NET MVC

I recently made changes to my MVC project by switching the default Bootstrap theme to Bootswatch - Cosmos. However, I am facing an issue with the Navbar as shown in the image below: View Header Display Issue Image Initially, I was using Bootstrap 3.0 and ...

Exploring the depths of JavaScript JSON elements

After processing my PHP code, it generates a JSON output that contains multiple entries in the same structure. Here is an example with two entries: { "0": { "campaign_id": "31", "title": "new title", "description": "new descrip ...

Conceal and Reveal Navigation Bar

On a mobile screen, here is how my navigation bar looks: Just to clarify, I am currently only focusing on making the nav bar responsive and not other content. The stylus code for the navigation bar is as follows: -> code in stylus!!! .nav display ...

Populate a dropdown menu using JSON data

I am working with an SQLite table that has columns for id and name. I have created a JSON array of rows from the autocomplete.php page. Now, I am trying to populate a dropdown list in my select element using this JSON data by utilizing jQuery and JavaScrip ...

Using JQuery to Refresh a Div and Trigger an API Call with a Click Event

Currently, I am working on developing a web application that generates random quotes dynamically. Using JQuery, I can successfully make an API call and retrieve JSON data to display a quote. To allow users to fetch new quotes with the click of a button, I ...

Text centered over an animated underline using CSS

Seeking help with my bootstrap 4 nav menu. I have implemented a CSS animation that creates an outward underline effect for the nav-link items. However, I am struggling to center the text above the line. Any suggestions on how to achieve this? I attempted ...

What is the best way to set values for the outcomes of a jQuery/AJAX post?

When sending data to a php page using jquery, I aim to receive the response from the page and store it in php variables on the original page without displaying results in the HTML or appending a DIV. Here's an example of how this can be achieved: Sam ...

The error message "window is not defined" occurs when the external file 'signalr.min.js' is included

Updates OpenTest --version 1.2.2 ChromeDriver 85.0.4183.87 Whenever I attempt to add the necessary external javascript files, it results in the following errors: Caused by: java.lang.RuntimeException: Failed to evaluate JavaScript code at line number 1. ...

Adjusting div to not be absolutely positioned

Trying to create a div with animated borders, but it only works when positioned absolutely in the center. For illustration, here is the HTML and CSS code: .bb, .bb::before, .bb::after { position: absolute; top: 0; bottom: 0; left: 0; right: 0; ...

The overlay image is not positioned correctly in the center

I am struggling with positioning a play icon overlay on the image in my list-group-item. The current issue is that the icon is centered on the entire list-group-item instead of just the image itself. I am working with bootstrap 4.4.1. Here is the HTML str ...

Leverage ngFor to loop through a "highly intricate" data structure

In my project, I have stored data in a JSON file structured as follows: { "name": { "source1": ____, "source2": ____, "source3": ____ }, "xcoord": { "source1": ____, "source2": ____, "source3": _ ...

Tips for organizing the router.js file in VueJs

With my router.js file currently reaching around 500 lines, Iā€™m looking for a better way to structure it. { path: "/", component: () => import("./../src/views/dashboard/Dashboard.vue"), meta: { auth ...

Having trouble with the jQuery toggle functionality not working as expected

I'm implementing a function where a div should increase in height and opacity when clicked, and then revert back to its original state when clicked again. I used the toggle function for this purpose, but the issue is that the button disappears when th ...