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

209
Views
Form not passing value on submit

I am struggling with getting my results from an API to show up on HTML page. Does work if the function is executed in the console.

<body>
<div>
    <form>
        <input type="text" id="search" placeholder="Enter person">
        <input type="submit" value="Submit" name="submit" onclick="fetchPerson()" />
      </form>
</div>
<div id="app"></div>
JS:
    function fetchPerson() {
    var input = document.getElementById('search').value;
    fetch(`notrevealingapi/api/name=${input}`)
    .then(res => res.json())
    .then(data => {
        console.log(data);
        const html = data.data
            .map(hit => {
                return `<p>Hits: ${hit.person}</p>`;
            })
            .join("");
        document.querySelector('#app').insertAdjacentHTML("afterbegin", html);
    })
    
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand your need correctly.
you want to populate the result in the <div id="app"> when a user clicks on the submit button.
There is two basic mistakes I can think of.

  1. You should use the button type instead of submit
  2. And use innerHTML instead of the insertAdjacentHTML. So it would look like
document.querySelector('#app').innerHTML = html
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!