Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!