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

128
Vistas
Changing global variable javascript

I want to use global variable number = 2, but when in input form something is put I want to change value of global variable because I'm going to use it in another function so at the beginning I want number = 2 but when other value is put in input form I want number to take that value.

<form onsubmit="return timed('commands')">
    <input type="number" name="a" id="commands"><br>
</form>
   var number= 2;
   function timed(id)
   {
       number=getElementById(id).value;
       return false;
   }
   
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add the event onchange to handle this:

<form onsubmit="return timed('commands')">
            <input type="number" name="a" id="commands" onchange="changeNumber(this.value)"/><br>
</form>

And add the function in the area:

function changeNumber(value){
            number=value
}

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