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

181
Views
Get Data from Input Field into Fetch Request in JavaScript

I am trying to get the data from a text field into my fetch request so that I can get a response from an API. The data should be sent to the fetch request onsubmit or onchange

How can I go about it?

HTML:

<div class="input-field">
    <input type="text" id="data" placeholder="submit token">
</div>

JS:

function dataFetch(url) {

  const data = document.getElementById("data").value;
  const myHeaders = { "x-data-token": data,
"x-data-access": "all-access")
}

  const requestOptions = {
    method: "GET",
    headers: myHeaders,
  };

  fetch(url, requestOptions)
    .then((res) => (res.ok ? res.json() : Promise.reject(res)))
    .then((data) => {
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!