Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

57
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;
   }
   
7 months 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
}

7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.