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

159
Vistas
Why is document.getElementById("element_id") returning the HTML input tag it is contained in?

I'm trying to get input from an input field. Such that when the user clicks a button, a JS function is called and the user input is used therein.

This is my html file:

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- contents of head here -->
        <script src="./src/main.js" type="module"></script> />
    </head>
    <body>
        <header>
            <form id="form">
                <input type="text" id="search" class="search" placeholder="Search TMDB" required>
                <input type="button" id="search_btn"" class="search_btn" value="Search"/>
            </form>
        </header>
    </body>
</html>

<!-- written by invalidrishav -->

The main.js mentioned in the script tag is as follows:

// other imports here
import { key } from './Api.js';

// other functions here

function search() {
    var input = document.getElementById("search_btn");
    console.log(input);
    window.open(`https://api.themoviedb.org/3/search/movie?api_key=${key}&query=${input}`,
        "TMDB", "menubar=1,resizable=1,width=500,height=500");
}

But when I click the search_btn button, this is what I get in console:

<input type="button" id="search_btn"" class="search_btn" value="Search" >

Also, it is not throwing any error in the console. How do I take the value of the user input?

about 4 years ago · Juan Pablo Isaza
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