You should be able to use something like the following to iterate through your <input> elements and pop off each name until they have each been exhausted :
// Your array
var array = ['Tom', 'Matt', 'Lucy', 'Suzanna', 'Hank'];
// Loop through the array and target the next available textbox
for(var input in document.getElementsByName('firstName')){
// If there are any names to use, use one
if(array.length > 0){
// Pop the next name off of your array and set the value
// of your textbox
input.value = array.pop();
}
}
If you have any issues actually using the above example to set the values, you can always use a slightly different loop to handle things :
// Your array
var array = ['Tom', 'Matt', 'Lucy', 'Suzanna', 'Hank'];
// Store your input elements
var inputs = document.getElementsByName('firstName');
// Loop through the array and target the next available textbox
for(var i = 0; i < inputs.length; i++){
// If there are any names to use, use one
if(array.length > 0){
// Pop the next name off of your array and set the value
// of your textbox
inputs[i].value = array.pop();
}
}
You can see a working example in action here and what the output using the data you provided might look like below :
