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

301
Views
Using map to get all values from input fields

Say there are numerous <input> and I wanted all the values as an array. I thought it'd be really easy to just do $("input").map(function(obj) { $(obj).val() }), but when I get that, I'm getting the error: Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')

This error is occuring within jQuery itself here:

var rreturn = /\r/g;

jQuery.fn.extend({
    val: function( value ) {
        var hooks, ret, isFunction,
            elem = this[0];

        if ( !arguments.length ) {
            if ( elem ) {
                hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
                ...

Any work around? Here's a fiddle: https://jsfiddle.net/jvbgo94f/1/

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

0

A bit different than what you're looking for, but the standard way to handle this is to use FormData.

If you wrap your inputs in a form element:

<form>
  <input name="a" />
  <input name="b" />
  <input name="c" />
</form>

Then, you can do something like this:

const formData = new FormData(
    document.querySelector('form')
);

for (const [key, value] of formData) {
  console.log({key, value});
}
about 4 years ago · Juan Pablo Isaza Report

0

You should use $(this) inside map to access that particular element.

$("#a").val("1");
$("#b").val("2");
inputs = $(".test").map(function() {
  return $(this).val();
});
console.log($(inputs));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="test" id="a" />
<input class="test" id="b" />
<input class="test" id="c" />

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!