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

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

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