Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
How to change input value as per custom numbers in JavaScript?

I want to change range value as per given custom value in screen shot. Right now I'm getting 1,2,3,4,5,6 values onchange of range but I need 6,12,24,36,48,60 values. How can I do this?

enter image description here

My Code:

<div class="slidecontainer">
  <input type="range"min="1" max="6" steps="1" value="1" id="myRange">
  <p>Value: <span id="demo"></span></p>
</div>

<script>
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = this.value;
}
</script>

ThankYou for your efforts!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can take a array and store the values you need in your slider.

<div class="slidecontainer">
  <input type="range"min="0" max="5" steps="1" value="0" id="myRange">
  <p>Value: <span id="demo"></span></p>
</div>

<script>
var values = ["6 mo","12 mo","24 mo","36 mo","48 mo","60 mo"];
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");

slider.oninput = function(){
    output.innerHTML = values[this.value];
};
slider.oninput();

</script>

about 4 years ago · Juan Pablo Isaza Relatório

0

The below snippet solves your problem

Changing this.value to set values in an array

<div class="slidecontainer">
  <input type="range"min="1" max="6" steps="1" value="1" id="myRange">
  <p>Value: <span id="demo"></span></p>
</div>

<script>
values = [6,12,24,36,48,60];
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = values[this.value-1];
}
</script>

about 4 years ago · Juan Pablo Isaza Relatório

0

If you have a fixed range you can use this method.

<div class="slidecontainer">
  <input type="range"min="1" max="6" steps="1" value="1" id="myRange">
  <p>Value: <span id="demo"></span></p>
</div>

<script>
var slider = document.getElementById("myRange");


var output = document.getElementById("demo");
output.innerHTML = slider.value === "1" ? '6 mo' : slider.value;

function myFunction(pos) {
  const myMonths = [6, 12, 24, 36, 48, 60]
  return myMonths[pos - 1] + ' mo'
}


slider.oninput = function() {
  output.innerHTML = myFunction(this.value);
}
</script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda