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

180
Visualizações
JS 'onclick' won't fire

Can anyone explain why the "onclick" part won't fire?

function displayHello() {

  let helloName = document.getElementByID('helloNameInput').value;

  // prints out the variable, to the button >>

  document.getElementByID("helloNameOutput").textContent = helloName
}
<!--Name input-->
<div class="mb-3">
  <label for="helloNameInput" class="form-label">Name:</label>
  <input type="text" class="form-control" name="helloNameInput" id="helloNameInput" placeholder="Enter a name" />
</div>

<!--Name output-->
<p class="lead" id="helloNameOutput"> </p>


<!--Display Hello! & Reset buttons-->
<div>
  <button class="btn btn-primary" id="displayHelloButton" onclick="displayHello()">Display Hello!</button>
  <button class="btn btn-danger" id="clearButton" onclick="clearName()">Clear</button>
</div>

PS:

I'm just learning JS, so, I'm not too familiar with a lot of stuff yet. (We just finished the HTML stuff last semester)

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

0

not getElementByID. use getElementById.

function displayHello() {
  let helloName = document.getElementById('helloNameInput').value;
  // prints out the variable, to the button >>
  document.getElementById("helloNameOutput").textContent = helloName
}
<!--Name input-->
<div class="mb-3">
  <label for="helloNameInput" class="form-label">Name:</label>
  <input type="text" class="form-control" name="helloNameInput" id="helloNameInput" placeholder="Enter a name" />
</div>

<!--Name output-->
<p class="lead" id="helloNameOutput"> </p>


<!--Display Hello! & Reset buttons-->
<div>
  <button class="btn btn-primary" id="displayHelloButton" onclick="displayHello()">Display Hello!</button>
  <button class="btn btn-danger" id="clearButton" onclick="clearName()">Clear</button>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

It does work, you just had a typo with getElementByID, it should be getElementById

function displayHello() {

  let helloName = document.getElementById('helloNameInput').value;

  // prints out the variable, to the button >>

  document.getElementById("helloNameOutput").textContent = helloName
}
<!--Name input-->
<div class="mb-3">
  <label for="helloNameInput" class="form-label">Name:</label>
  <input type="text" class="form-control" name="helloNameInput" id="helloNameInput" placeholder="Enter a name" />
</div>

<!--Name output-->
<p class="lead" id="helloNameOutput"> </p>


<!--Display Hello! & Reset buttons-->
<div>
  <button class="btn btn-primary" id="displayHelloButton" onclick="displayHello()">Display Hello!</button>
  <button class="btn btn-danger" id="clearButton" onclick="clearName()">Clear</button>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

In case others run into this same issue, I've uploaded a screenshot of the "git change log", that has all the corrections to the above, so that it worked as intended. ^_^

enter image description hereenter image description here

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