Looking to create a JSON structure with name and value pairs such as name:"john".
Check out the code snippet below:
var allFields = [];
var inputs = document.getElementsByTagName('input');
for(var i=0; i<inputs.length;i++){
name = inputs[i].name;
item = inputs[i].value;
allFields.push({name: item});
}
var alleFelder = JSON.stringify(allFields);
alert(alleFelder);
The issue I'm facing is that "name" is hardcoded into the JSON.
Instead of having: name:"john", lastname:"brooks", birthdate:"1.1.1999"
I end up with: name:"john", name:"brooks", name:"1.1.1999"