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

158
Views
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
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!