Tips for making Slider display the next or previous slide when span is clicked

I have implemented a mix of bootstrap 3 and manual coding for my project.

While the image thumbnails function correctly when clicked, the span arrows do not navigate to the next or previous images as intended.

Below is the code snippet:

var maximages = 6;
var startpath = "imgs"
var extension = ".jpg"


function calcslide(x) {
    var currentimage = document.getElementById("bigpic").src;
    var dotat = currentimage.indexOf(extension);
    var stringnumber = currentimage.substr(dotat - 2, 2);
    var nextnum = parseInt(stringnumber) + x;
    if (nextnum < 1) {
        nextnum = maximages;
    }
    if (nextnum > maximages) {
        nextnum = 1;
    }
    var twodigitnum = ("0" + nextnum).slice(-2);
    var showimg = startpath + twodigitnum + extension;
    showbig(showimg);
}

function showbig(pic) {
    document.getElementById("bigpic").src = pic;
}
.slider {
    text-align: center;
}

#bigpic {
    height: 500px;
}

.thumbs img {
    height: 100px;
    padding: 20px 0 20px 0;
}
 <div class="slider">
                <span class="glyphicon glyphicon-chevron-left btn btn-lg" alt="previous" onclick="calcslide(-1)"></span>
                <img src="imgs/slider01.jpg" id="bigpic" />
                <span class="glyphicon glyphicon-chevron-right btn btn-lg" alt="next" onclick="calcslide(1)"></span>
                <div class="thumbs">
                    <span class="glyphicon glyphicon-chevron-left" alt="previous" onclick="calcslide(-1)"></span>
                    <img src="imgs/slider01.jpg" onclick="showbig(this.src)" />
                    <img src="imgs/slider02.jpg" onclick="showbig(this.src)" />
                    <img src="imgs/slider03.jpg" onclick="showbig(this.src)" />
                    <img src="imgs/slider04.jpg" onclick="showbig(this.src)" />
                    <img src="imgs/slider05.jpg" onclick="showbig(this.src)" />
                    <img src="imgs/slider06.jpg" onclick="showbig(this.src)" />
                    <span class="glyphicon glyphicon-chevron-right" alt="next" onclick="calcslide(1)"></span>
                </div>
            </div>

Answer №1

Your path construction is missing a slash / and a prefix.

Original Path:

 var showimg = startpath + twodigitnum + extension

Updated Path:

 var showimg = startpath + '/slider' + twodigitnum + extension

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

Expand the table in the initial state by using CSS to collapse the tree

I am struggling to collapse the tree view and need assistance. Below is the code snippet I've added. My goal is to have each node in the tree view initially collapsed and then expand a particular node on user interaction. For example, when I execute ...

Top method for preventing an HTTP 403 error when receiving the Set-Cookie header in order to establish the CSRF Cookie

As I interact with a REST API that includes CSRF protection measures, I am facing a common hurdle. Successfully obtaining the token and sending it back to the server seems to work smoothly. However, encountering an HTTP 403 error arises when initiating t ...

Triggering div visibility based on jQuery select change event

I am currently working on a form feature that involves showing a div when a specific option in a select element is chosen, and hiding the div when the option is not selected. Here is the current structure of my markup: Here is the current HTML markup I ha ...

Guide on uploading files using Vue.js2 and Laravel 5.4

I'm currently attempting to implement an image upload feature using Laravel for the backend and Vue.js2 for the frontend. Here are snippets from my code: addUser() { let formData = new FormData(); formData.append('fullname', this.n ...

Geolocation API for determining altitude

When using the geolocation API, I am experiencing no issues with latitude and longitude. However, I have encountered a problem with Altitude. For instance, when I retrieve the coordinates for my current location using my mobile phone with integrated GPS, i ...

Text affected by mix-blend-mode glitch

Currently, I am experimenting with knockout text using the mix-blend-mode property. An interesting issue arises when I examine the responsiveness of my design by utilizing Developer tools in the browser console - there are faint lines that momentarily appe ...

Issue: AngularJS modal not appearing when utilizing partial for template URLExplanation: The Angular

I am having trouble with a modal in a partial file that is supposed to be loaded into my main view using an ng-include tag. However, the template cannot be found and I do not see it being loaded in the console or network tab. The error message I receive is ...

Separating vendor and application code in Webpack for optimized bundling

Recently, I created a React+Webpack project and noticed that it takes 60 seconds to build the initial bundle, and only 1 second to append incremental changes. Surprisingly, this is without even adding my application code yet! It seems that the node_modules ...

Incorporating Bootstrap's Inline Design Elements

I am having trouble aligning a series of elements horizontally using bootstrap as shown in the example image below: Whenever I add the "form-control" class to the input element, it gets pushed down below the other elements. I have experimented with differ ...

Trouble with 'this.function' and handling scope within my code

Hi there! I'm having an issue with this code snippet: Whenever I reach line 109, I encounter an error message that reads "TypeError: Result of expression 'this.allVarsDefined' [undefined] is not a function." I find scope in javascript to b ...

Trying to decide between using a Javascript or HTML5 PDF Editor?

I am in need of a solution that enables users to edit PDF files directly on an ASP.NET web page. This functionality is intended for creating templates and adding blocks/form fields to existing PDFs, complete with rulers and other necessary features. Desp ...

Is it possible to utilize $regex alongside $all in mongoDB?

In my current project, I am facing a challenge where I need to handle an array of strings received from the frontend. Each document in my mongoDB database also has its own array of keywords. The tricky part is that the strings sent from the frontend migh ...

Animating the maximum height causes a delay in the performance of other elements

Attempting to adjust the maximum height of a ul. When the max-height property changes (via toggling a class), the height shifts immediately, while the items below the ul maintain the animated height as expected. var expander = $('.skill-expand&apos ...

Converting a JavaScript array to a PHP array using POST request

In my JavaScript script, I have the following code: cats = []; cats.push(cat1); cats.push(cat2); $.post( URL+"/edit-article.php", { id: artId, title: "PZujF0 wxKLCW", content: "ILEn3o oU9Ft6oU5", author: author, cat_id: cats } ).done(function( data2 ) ...

Creating distance between two text boxes in bootstrap is easy with the use of margins. By

I am looking to create a small white space between two text boxes. <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" /> <div class="row col-lg-12 col-sm-12"> <div class ...

How to create a stunning Bootstrap Jumbotron with a blurred background that doesn't affect the

I need help making my Jumbotron image blurry without affecting the text inside it! Below is the code from my index.html and style.css files. Any assistance would be greatly appreciated. body { background-image: url(bg1.png); background-repeat: repea ...

Javascript: struggling with focus loss

Looking for a way to transform a navigation item into a search bar upon clicking, and revert back to its original state when the user clicks elsewhere. The morphing aspect is working correctly but I'm having trouble using 'blur' to trigger t ...

What is the best way to arrange <div> elements with text inside without moving the text?

I need help figuring out how to stack one or more <div> elements on top of another <div> element while maintaining the text content within each. My issue is illustrated in this fiddle: https://jsfiddle.net/rd268ucy/1/. When attempting to drag o ...

Linking Java objects with Node.js variables

In this snippet of code, I am utilizing the 'java' module in node.js to create Java objects. Specifically, I am creating four Java objects and aiming to consolidate them as a single object by using the variable 'args' to store these Jav ...

Could not locate the express.js file

Currently in the process of learning express/node.js, but struggling to locate the page at localhost:3000/info You can view screenshots of my code below ...