Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda