Hello I am looking to create a JavaScript object to store values captured from some fields. I have dynamic fields where the user can add more fields to the page.
I am able to capture and store the fields in an object using the below code.
var attributes = document.getElementsByName("attribute[]");
var locations = document.getElementsByName("location[]");
var len = attributes.length;
var data = []
for(var i = 0; i < len; i++){
var element = {
"Attribute": attributes[i].value,
"Location": locations[i].value,
};
data.push(element);
};
Recently I had to add a <select> field called "Methods" to the dynamic fields, that allows users to select multiple methods in the drop down. I am struggling on how I can get the array of selected methods per "Attribute".
Any help is greatly appreciated.
selectelements have themultipleattribute?[]in the name!