Get the values of all inputs with same class as an array

If all your inputs share the same class say "class1" then you can select all such inputs using this

var inputs = $(".class1");

Then you can iterate over the inputs any way you want.

for(var i = 0; i < inputs.length; i++){
    alert($(inputs[i]).val());
}

you can user jquery each function ...

$('.spocNames').each(function(){
  alert(this.value);
}

To get the values of each element as an array you can use map():

var valueArray = $('.spocName').map(function() {
    return this.value;
}).get();

Or in ES6 (note that this is unsupported in IE):

var arr = $('.spocName').map((i, e) => e.value).get();

You can then use this array as required to save to your database - eg. as a parameter in an AJAX request.

Tags:

Jquery