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

346
Visualizações
after set default value attribite can't re-assign it

I'm trying to do so "Projectile motion" experiment.

in HTML

<div>
    <label for="angle">Angle</label>
    <input id="angle" name="angle" type="number" max="90" min="0" value=50 ></input>
    <label for="velocity">Velocity</label>
    <input id="velocity" name="velocity" type="number" value=150></input>
    <button id="launch">Launch</button>
    <button id="reset">Reset</button>
</div>

And in JS:

let v = document.getElementById("velocity").value;
let degreeAngle = document.getElementById("angle").value;

I can change the value of V and Angle in the input by this is no effect on the value. (always v is 150 and angle 50)

why ? and how can I change those values?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You seem to be looking for a way to respond to changes in the values set by the user. What you're looking for is an event handler (https://developer.mozilla.org/en-US/docs/Web/Events/Event_handlers).

Event handlers allow you to attach a callback function to an element and have it execute whenever some event occurs.

You can attach an event handler to the click event on the #launch button and run your calculations/simulation like so:

function onLaunchClicked() {
  let v = document.getElementById("velocity").value;
  let degreeAngle = document.getElementById("angle").value;
  // Run simulation
}

let launchButton = document.getElementById("launch");
launchButton.addEventListener("click", onLaunchClicked);
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