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

148
Visualizações
Interpreting Input in Javascript

I made some HTML code in replit.com.

Please excuse me if the question I ask is very dumb, since I am new to HTML & JS.

I want the user to type something in the input field and click the "Click Me" button. I expected the button to change its text to whatever the user typed. But instead, it just went blank.

Here is my code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <label for="text">Type Some Text:</label><br>
    <input type="text" id="type" name="text"><br><br>
    <button type="button" style="background-color: khaki; margin-left: 20px; padding-left: 30px; border: solid 5px; border-radius: 40px; padding-right: 450px; font-size: 18px" onclick="Click()" id="click">Click Me!</button>
    <script>
      function Click() {
        text = document.getElementById("type").innerHTML;
        document.getElementById("click").innerHTML = text;
      }
    </script>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

https://codepen.io/jacobcambell/pen/OJjyoWW

A few things to consider here.

First, to get the value of an HTML input, you need to use .value instead of .innerHTML, for example:

text = document.getElementById("type").value;

Next, (optionally) you can just call alert() instead of window.alert() as most browsers know how to handle it correctly.

Finally, to change your button, you need to set the innerHTML of the button to your text variable, right now you're just setting it equal to "text" which is a string in JavaScript. You are literally making your button say "text"

Also, I would recommend using let to declare your variables here.

A final version of your Click function might look like:

function Click() {
    let text = document.getElementById("type").value;
    alert(text)
    document.getElementById("click").innerHTML = text;
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Use this:

function Click() {
        text = document.getElementById("type").value;
        document.getElementById("click").innerHTML = text;
      }

Also, you can also use this:

function Click() {
        document.getElementById("click").innerHTML = document.getElementById("type").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