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

279
Views
How can i collect data from form with javascript and store it in variables?

Hey lets say i have a simple form like this:

<form>
<label for="name">Enter name:</label>
<input type="text" id="name">
<label for="surname">Enter surname:</label>
<input type="text" id="surname">
<label for="number">Phone number:</label>
<input type="text" id="number">
</form>

and in javascript, instead of getting values one by one and storing them with queryselectors, is there a way i can select the whole form and get its input values? also after that how can i store them in variables so i can use them later? for example, print them one by one.

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

0

You can use FormData:

let myForm = document.getElementById('myForm');
let formData = new FormData(myForm);
console.log(formData.entries());
<form id="myForm">
  <label for="name">Enter name:</label>
  <input type="text" id="name">
  <label for="surname">Enter surname:</label>
  <input type="text" id="surname">
  <label for="number">Phone number:</label>
  <input type="text" id="number">
</form>

about 4 years ago · Juan Pablo Isaza Report

0

Bobi. You may use javascript FormData() method.

var formData = new FormData(document.querySelector('form'))

Please check this document. https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData

Hope this helps. Happy coding~ :)

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!