Starting by your HTML that has two main issues. The first is that you use the same form field for any of the fields as well you have the same ID for all of the fields. This has as effect to make fields looks like as there is only one.
<input type="hidden" name="uID" id="uID" value="251|0">
<input type="hidden" name="uID" id="uID" value="252|0">
<input type="hidden" name="uID" id="uID" value="253|0">
<input type="hidden" name="uID" id="uID" value="254|0">
<input type="hidden" name="uID" id="uID" value="0|0">
In order to solve this issue you should either update your HTML to looks like that:
<input type="hidden" name="uID[]" id="uID-1" value="251|0">
<input type="hidden" name="uID[]" id="uID-2" value="252|0">
<input type="hidden" name="uID[]" id="uID-3" value="253|0">
<input type="hidden" name="uID[]" id="uID-4" value="254|0">
<input type="hidden" name="uID[]" id="uID-5" value="0|0">
of like this:
<input type="hidden" name="uID-1" id="uID-1" value="251|0">
<input type="hidden" name="uID-2" id="uID-2" value="252|0">
<input type="hidden" name="uID-3" id="uID-3" value="253|0">
<input type="hidden" name="uID-4" id="uID-4" value="254|0">
<input type="hidden" name="uID-5" id="uID-5" value="0|0">
In the first solution, if you post the form, the data will go to your server will be an array with the values of all your fields.
In the second solution I have send you, you will just have multiple variables in your request.
Now in order to get the values you should run the following code:
// Isolate the code inside a Immediately-Invoked Function Expression (IIFE)
(
function ( $, window, undefined ) {
// Create a variable that is going to hold all the hidden fields
var $hidden_inputs = null;
// Responsible to iterate over the elements found in your
// HTML, and returns the values in the format of val,val,val
var get_values = function get_values ( ) {
// Register an array variable that is going
// to hold the values of all the found fields
var $string_parts = [];
// Iterate over the found fields
$hidden_inputs.each(
function() {
// And push the values of those fields into the
// values array container
$string_parts.push( $( this ).val() );
}
);
// Finally return the array values joined with commas
return $string_parts.join( ',' );
}
// When the document is loaded
$( document ).ready(
function () {
// Query the document for the hidden fields that works
// like that:
// Find all the input fields with
// type="hidden" that the
// name attribute contains the string uID
$hidden_inputs = $( 'input[type="hidden"][name*="uID"]' );
// If the jQuery found more than 0 elements
if ( 0 < $hidden_inputs.length ) {
// Get the field values and save them into the
// $values variable.
var $values = get_values();
}
}
);
}
)( jQuery, this );
You can also find a running example here : jsFiddle
<input />elements with the same name in the first place? Also, IDs are supposed to be unique within the DOM.$("input[name='uID']").map((x, elm) => elm.value).get().join(',')