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

125
Visualizações
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 Respostas
Responde à pergunta

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 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