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

182
Visualizações
Slidebar which can be adjusted manually

I did a Slidebar (0-99) which is working well. I want to add 2 buttons to manually change it (first button -1 ; second button +1). It was working well with my "-1" code for the first button, but the second one isnt working and I dont understand why. (It add 1 but for example if my slidebar is at 50, when i click its not going to 51 but 501).

Here is my code :

<div>
   <button id="moins1" onclick="moins1()">MOINS 1</button>
   <span class="unselectable rangeValue1" id="rangeValue1">RR</span>
   <Input class="range" type="range" name="BarreRR" value="0" min="0" max="99" onChange="rangeSlide1(this.value)" onmousemove="rangeSlide1(this.value)"></Input>
   <button id="plus1" onclick="plus1()">PLUS 1</button>
</div>
<script type="text/javascript">
   function rangeSlide1(value) {
    document.getElementById('rangeValue1').innerHTML = value;
   }
   
   function moins1(){
    var Yop = document.getElementById('rangeValue1').textContent;
    Yop -=1;
    document.getElementById('rangeValue1').innerHTML = Yop;
    console.log(Yop);
   }
   function plus1(){
    var Yop = document.getElementById('rangeValue1').textContent;
    Yop +=1;
    document.getElementById('rangeValue1').innerHTML = Yop;
    console.log(Yop);
   }
</script>

Thanks for help, Zartex.

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

0

The issue is that textContent returns string and using + operator will try to concatenate the values. So you can parse it. But I would recommend directly connecting your range with displayed value and only alter the range using the buttons or change them together for example:

   function rangeSlide1(value) {
        document.getElementById('rangeValue1').innerHTML = value;
      }
    
      function moins1() {
        let range = document.querySelector('.range')
        if (range.value != 0) {
          let newValue = range.value - 1
          document.getElementById('rangeValue1').innerHTML = newValue
          range.value = newValue
        }
      }
    
      function plus1() {
        let range = document.querySelector('.range')
        if (range.value < 99) {
          let newValue = Number(range.value) + 1
          document.getElementById('rangeValue1').innerHTML = newValue
          range.value = newValue
       }
      }
    <div>
      <button id="moins1" onclick="moins1()">MOINS 1</button>
      <span class="unselectable rangeValue1" id="rangeValue1">RR</span>
      <Input class="range" type="range" name="BarreRR" value="0" min="0" max="99" onChange="rangeSlide1(this.value)" onmousemove="rangeSlide1(this.value)"></Input>
      <button id="plus1" onclick="plus1()">PLUS 1</button>
    </div>
    
   

Considering your range is limited from 0 to 100 I added condition not to go under 0

about 4 years ago · Juan Pablo Isaza Relatório

0

it will help you, Yop value always in "50" + 1 it will return by concat 501 so parseInt your string and add/minus by 1

function moins1(){
     var Yop = document.getElementById('rangeValue1').textContent;
     Yop = parseInt(Yop)-1;
     document.getElementById('rangeValue1').innerHTML = Yop;
    console.log(Yop);
 }
function plus1(){
       var Yop = document.getElementById('rangeValue1').textContent;
        Yop = parseInt(Yop)+1;
        document.getElementById('rangeValue1').innerHTML = Yop;
        console.log(Yop);
  }
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