I want to automatically change the selection on radio buttons at regular interval. I'm calling setTimeOut in for loop after every 2000ms, but radio button selection is not changing with respect to the interval I've set. Here's my code: HTML:
<input type="radio" id="carousel1" name="carousel" checked="checked">
<input type="radio" id="carousel2" name="carousel">
<input type="radio" id="carousel3" name="carousel">
Javascript:
function autoSlideCarousel() {
for (var n = 1; n <= 3; n++) {
setTimeout(autoSlide(n), 2000);
}
}
function autoSlide(n) {
console.log(n);
document.getElementById("carousel"+n).checked = true;
}
window.onload = autoSlideCarousel();
Here's JSFiddle link for more clarity: https://jsfiddle.net/16zmfb12/1/
Appreciate your help.