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

211
Visualizações
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 Respostas
Responde à pergunta

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 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