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

164
Views
FormData is empty in JS
<form class="form">
  <div class="container">
    <label>URL</label>
    <input id="data-url" value="val" type="text" />
  </div>
</form>

const formData = new FormData(document.querySelector('.form'));
console.log([...formData])

It is simplified version of HTML, but basically label and input tags are descendants of form. I am trying to get value of input and name of the label using FormData API, but it is empty for some reason.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need the give the input a name:

form.addEventListener('submit', function(e) {
  e.preventDefault();
  const formData = new FormData(form);
  console.log([...formData])
})
<form class="form" id="form">
  <div class="container">
    <label>URL</label>
    <input id="data-url" value="val" type="text" name="data-url" />
  </div>
  <button>View form data</button>
</form>

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