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

220
Visualizações
Label Tag value not getting populated

I have the following code. I want to take input from a user and display the twice of
that number on the page. I am using document.getElementById("output").value=value; so that the label tag with id output value is changed or in other words it becomes like
10 when user has entered 5 in the input box but I cannot see this value 10. What could be going wrong here?

Separately I am sure it's not the best way to design this kind of thing. If anyone could
share insights on how to write a better code, it would be great.

<!DOCTYPE html>
<html>
  <head>
    <title>Title</title>
  </head>
  <body>
    <label for="input">Enter number :</label>
    <input id="text" type="text"></input><br><br>
     
    <input id="button" type="submit"></input><br>
    <label id="output"></label>
<script>
    let inputButton = document.getElementById("button");
    inputButton.addEventListener("click", function(){
        let value = parseInt(document.getElementById("text").value);
        value=value*2;
        document.getElementById("output").value=value;
    });
   
</script>
  </body>
</html>

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

0

<label> doesn't have value, instead use textContent like:

let inputButton = document.getElementById("button");
inputButton.addEventListener("click", function() {
  let value = parseInt(document.getElementById("text").value);
  value = value * 2;
  document.getElementById("output").textContent = value;
});
<label for="input">Enter number :</label>
<input id="text" type="text"><br><br>

<input id="button" type="submit"><br>
<label id="output"></label>

Reference:

  • <label>
  • textContent
  • input

PS: I also linked the inputs link to you because I saw you were trying to close them, read that too well

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