Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda