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

247
Vistas
user input in javascript need to reloade the page every time for change the value

I build a web site that take from the user number and perform specific math operations by clicking in buttons, for example user type '100' and click at 15% button the app will print in the console log 15 now the user change the previous value at the input field to '80 and press the same button 15% it should print '12' but no it still the same result '15' if I want the result I need to reload the page, how can I make the result change every time the user change the input value in javascript, here simple code for more detail:

HTML:

<input type="number" id="ID">
<button id="Button">15%</button>

JAVASCRIPT:

const input= document.getElementById("ID");
const button = document.getElementById("Button");
button.addEventListener('click', ()=>{
 const operation = input.value * 0.15;
 console.log(operation);
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're not resetting the input value from the memory stack, so when you try to call the variable value your program uses the first stored value to that variable. Try to instantiate your input variable in the event listener function so that each time you call this operation you are actually taking the new value in your variable.

    <div id="result"></div>
    <input type="number" id="ID">
<button id="Button">15%</button>


const button = document.getElementById("Button");
button.addEventListener('click', ()=>{
 const input= document.getElementById("ID");
 const operation = input.value * 0.15;
 console.log(operation);
 document.getElementById("result").innerHTML=`${operation}`;
});
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