Hi all,
I am trying to create a ‘Review Carousel’, but I am struggling with creating working buttons through JavaScript - is there an appropriate way to link to an internal file using JavaScript? I would essentially like to call on a function that redirects the user to the next review and also disables non-applicable buttons. This is what I have so far:
SIDENOTE I have two html documents - one is index and the other index2, which is what is referenced in the location.href section of the functions. These are the documents I am trying to link to the buttons. It seems as though location.href is not applicable here - is there another method I should be using?
JS:
const buttonRight = document.getElementById('buttonRight');
const buttonLeft = document.getElementById('buttonLeft');
let currentIndex = 0;
function nextReview() {
if (currentIndex == 0) {
let newPage = location.href = "./ReviewCarousel/index2.html";
return newPage;
} else {
buttonRight.disabled = true;
}
}
function previousReview() {
currentIndex = 1;
if (currentIndex > 0) {
let prevPage = location.href = "./ReviewCarousel/index.html";
return prevPage;
} else {
buttonLeft.disabled = true;
}
}```
HTML:
Review Page
Our Reviews:
John Doe
Full-Stack Developer
This website is amazing - really useful learning experience. I hope the creator continues on his developer journey and we see more from him in the future!
Previous Next