Hello I have an input range with values 0-380 and I want to disable some value, like ID 30. So when I select 29 and press the right arrow, it must be change to 31.
1 Answer
Just check if the slider.value is on a certain number, and if it is, do something to avoid the number. Here's a simple way I thought to fix this, but this is by no means the best way.
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
function removeNum(num) {
if (slider.value == num-1) {slider.value++}
else if (slider.value == num+1) {slider.value--}
}
slider.oninput = function() {
output.innerHTML = this.value;
removeNum(10) //Doesn't allow slider to go to number 10
}
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
2 Comments
Balázs Fajd
Thank you for the quick answer, its almost working, but now the value stuck in 9-11. (with using the keypad arrows)
Scollier
Perhaps this article can help you? stackoverflow.com/questions/23014375/…