Ascending with Progress Indicator Slider

After successfully creating a Bootstrap 5 Carousel with an automated count for each slide (limited to 4) and a corresponding progress bar, I encountered an issue with getting the previous button to function correctly. While clicking the next button works seamlessly, figuring out how to make the previous button work by decrementing the count and adjusting the progress bar has been challenging.

To resolve this issue, a revised script can be implemented:
var clicks = 1;
var number = 0;
var elem = document.getElementById("myBar");

function onSelect() {
clicks -= 1;
}

function onClick() {
clicks += 1;

if (clicks === 5) {
clicks = 1;
} 

switch(clicks){
case 1:
elem.style.width = '25%';
break;
case 2:
elem.style.width = '50%'; 
break;
case 3:
elem.style.width = '75%'; 
break;
case 4:
elem.style.width = '100%'; 
break;
}

document.getElementById("testimonial-count").innerHTML = clicks;

};
... CSS stylesheet and HTML structure remain intact ...

As I navigate through this challenge, I'm exploring options to introduce a new variable that mirrors "clicks" in order to facilitate the subtraction process and adjust the width of the progress bar accordingly. As a newcomer to this field, any guidance or assistance would be greatly appreciated!

Answer №1

Most of the solution is already provided, but the missing piece is the logic to modify the CSS based on user interaction.

I've included the modified example that covers both forward and backward progress directions.

var clicks = 1;
var number = 0;
var elem = document.getElementById("myBar");

function previousStep() {
  clicks -= 1;
  if (clicks === 0) {
    clicks = 4;
  }
  displayProgress();
}

function nextStep() {
  clicks += 1;
  if (clicks === 5) {
    clicks = 1;
  }
  displayProgress();
};


function displayProgress() {
  if (clicks === 1) {
    elem.style.width = 25 + '%';
  }

  if (clicks === 2) {
    elem.style.width = 50 + '%';
  }

  if (clicks === 3) {
    elem.style.width = 75 + '%';
  }

  if (clicks === 4) {
    elem.style.width = 100 + '%';
  }

  document.getElementById("testimonial-count").innerHTML = clicks;
}
/* TESTIMONIAL */

.testimonial {
  margin: 5% auto;
}
...<!--Remaining CSS styles are retained for testimonial section--->... 
...

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

Enhancing user experience with Jquery datepicker and executing multiple actions on select

I am working on a form that includes a jQuery date selector and radio buttons structured in a table as shown below: <table> <tr> <td> <input type="text" id="5506_datepick_1"></input> </td> <td&g ...

Safari has trouble with AJAX cross-origin requests, while Chrome and Firefox handle them without issue

I am developing a Shopify app that utilizes script tags and requires an ajax call to our server to retrieve necessary information about the shop. While everything seemed to be functioning correctly, my colleague pointed out that it was not working on his i ...

Try out a Vue.js Plugin - A Comprehensive Guide

Currently, I am delving into the world of Vue.js. In my journey, I have crafted a plugin that takes the form of: source/myPlugin.js const MyPlugin = { install: function(Vue, options) { console.log('installing my plugin'); Vue.myMetho ...

Retrieving information through a jQuery ajax call

I've been working on creating an AJAX filter for a car list, but I've hit a roadblock in the final stage. My setup involves two files: index.php and filter.php. Within index.php, I have a form with dropdown lists and sliders. Here's the cod ...

Retrieve text from a dropdown menu while excluding any numerical values with the help of jQuery

I am currently implementing a Bootstrap dropdown menu along with jQuery to update the default <span class="selected">All</span> with the text of the selected item by the user. However, my objective is to display only the text of the selected it ...

The Express.js application functions properly on a local environment, but encounters issues when deployed on Heroku

Currently, I am experiencing an issue with deploying a music visualizer that I created. It seems to work perfectly in all scenarios except when I click on a song to play from the search bar, where I keep encountering a '503 (Service Unavailable)' ...

Problem with Snowpack's internal module import paths

While working on a project, I am using npx snowpack build --watch instead of the dev command because of a Flask backend. However, I am facing issues with internal imports, specifically modules importing dependencies like Bootstrap importing Popper. The pr ...

A guide to importing a Vue component in a JavaScript file

I am looking to achieve a specific behavior in my project: depending on a condition stored in my database, I want to load a particular vue.component instead of another. For example, within a file named discover.js, there is the following code: Vue.compone ...

PHP: the images uploaded are not located within the designated folder

Having trouble uploading multiple images to a folder and saving them in the database? The images are not moving to the folder, even though the code works on localhost. Here is the code snippet: var abc = 0; // Declaring and defining global incremen ...

How come the styles in my CSS file aren't being applied to my images based on their class or ID?

When I apply a className or id to my img tag in my JavaScript (using React.js) and then add a style that references that id or class, the style does not get applied. However, when I do the same for a div, everything works perfectly fine. <--JavaScript- ...

Disable button with Checkbox Javascript functionality

In my PHP code, I have an array of users that I pass to the view (in Laravel) and use a foreach loop to display all users in a table. Everything is working fine so far. However, I want to make a "send" button visible when a checkbox is clicked, instead of ...

Encountering a fresh issue after updating to TS version 4.4.3 while accessing properties of the top "Object may be 'null'."

After upgrading my project to TypeScript 4.4.3 from 3.9.9, I encountered a change in the type declarations for the top property. My project utilizes "strictNullChecks": true, in its configuration file tsconfig.json, and is browser-based rather t ...

URL Construction with RxJS

How can I efficiently create a urlStream using RxJS that incorporates multiple parameters? var searchStream = new Rx.ReplaySubject(1); var pageStream = new Rx.ReplaySubject(1); var urlStream = new Rx.Observable.create((observer) => { //Looking to ge ...

Reduce the text of the link

Trying to simplify a task, but I'm struggling with the solution. What I want to achieve is shortening a link to 30 characters and adding ... at the end if it's longer. Also, I'd like to make it possible to see the full link on hover similar ...

Programme for Server Login

After creating my own server, I attempted to implement a login feature to restrict access to its files. Unfortunately, using Javascript for this task proved to be insecure as usernames and passwords could easily be viewed in the source code: <form name ...

What is the best method for exporting a MapboxGL map?

I am currently utilizing mapboxGL to display maps on a website, and I am interested in exporting the map as an image with the GeoJSON data that has been plotted. I attempted to use the leaflet plugin for this purpose, but it was unable to render clusters ...

Attempting to transmit information to database using AJAX in the context of CodeIgniter

I'm having some trouble with my AJAX setup. It doesn't seem to be posting any data to the database, despite trying various solutions I found online. That's why I've turned to this platform for help. When testing in Postman and sending ...

Utilize JavaScript to dynamically deactivate hyperlinks during runtime

Utilizing Bootstrap <ul class="nav nav-pills nav-stacked col-sm-2 hidden" id="menu"> <li role="presentation" id="LiNewsFeed"><a href="javascript:GetNewsFeed();">News Feed</a></li> <li role ...

Ways to include x-api-key in Angular API request headers

I am attempting to include the x-api-key header in the headers, as shown below: service.ts import { Injectable } from '@angular/core'; import { Http, Headers, RequestOptions, Response } from '@angular/http'; import { Observable } from ...

Move to the following <article>

I am currently working on developing a JavaScript function that will automatically scroll to the next article whenever the down arrow key is pressed. The challenge I am facing is that my HTML elements are all dynamic and are simply article tags without any ...