I want to display the next carousel-item when Id="item1" of Radio Button is selected by default and Id="item2" is pressed.
It would be best if this could be done without using Javascript.
If Javascript is necessary, please let us know how to do it or give us a reference site.
<div class="container-fluid">
<div class="row align-items-center">
<div class="col-auto">
<h3 class="mb-3">Recommended</h3>
</div>
<div class="col-12 p-0 mb-3">
<div id="carouselExampleIndicators2" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row g-6 border border-dark-3">
<div class="col-xl-2 col-lg-4 col-md-3 col-xs-1 p-0 ps-2">
<div class="card p-2 border-1 rounded-0 h-100">
<img class="card-img-top custom-card-img-top" alt="..." src="">
{{-- Todo: Change to heart icon and button by conditional --}}
<i class="fa-solid fa-heart position-absolute top-0 end-0 m-3 heart-icon"></i>
<div class="card-body p-2">
...
</div>
</div>
</div>
</div>
</div>
{{-- This is second Item --}}
{{-- Todo: Add JavaScript if the radio is pressed it should show up second item --}}
<div class="carousel-item">
<div class="row g-6 border border-dark-3">
<div class="col-xl-2 col-lg-4 col-md-3 col-xs-1 p-0 ps-2">
<div class="card p-2 border-1 rounded-0 h-100">
<img class="card-img-top custom-card-img-top" alt="..." src="">
{{-- Todo: Change to heart icon and button by conditional --}}
<i class="fa-solid fa-heart position-absolute top-0 end-0 m-3 heart-icon"></i>
<div class="card-body p-2">
...
</div>
</div>
</div>
</div>
</div>
{{-- This is second Item --}}
</div>
</div>
</div>
</div>
<div class="col-12 text-center">
<div class="form-check form-check-inline m-0">
<input class="form-check-input" type="radio" name="item-recommended" id="item1" checked>
</div>
<div class="form-check form-check-inline m-0">
<input class="form-check-input" type="radio" name="item-recommended" id="item2">
</div>
<div class="form-check form-check-inline m-0">
<input class="form-check-input" type="radio" name="item-recommended" id="item3">
</div>
</div>
</div>
2
Answers
Solve this problem!! Thank you for helping me !!
you would definitely need a javascript for this:
logic is this -> you add an event listener when on the radio inputs when they are clicked you will change the dom with javascript. you will also need a images for the carousel. the radio input depends on how many images you have.
here’s the code by this you can achieve
if you want to create a scratch carosel here’s the link for the instructions:
click here