I have a form with multiple input field, I need to get value of that form and pass into JSON object as shown below. each of the field will have object in the array. How Do I get all multiple field to pass as Array of Object.(form will allow to add multiple field)
I'm using JavaScript and jQuery to get all Value.
<div class="info">
<div class="field">
<label> field 1 </label>
<input placeholder="Name" class="name" type="text">
<input placeholder="email" class="email" type="text">
<input placeholder="Address" class="address" type="text">
</div>
<div class="field">
<label> field 2</label>
<input placeholder="Name" class="name" type="text">
<input placeholder="email" class="email" type="text">
<input placeholder="Address" class="address" type="text">
</div>
<div class="field">
<label> field 3 </label>
<input placeholder="Name" class="name" type="text">
<input placeholder="email" class="email" type="text">
<input placeholder="Address" class="address" type="text">
</div>
<div class="field">
<label> field 4 </label>
<input placeholder="Name" class="name" type="text">
<input placeholder="email" class="email" type="text">
<input placeholder="Address" class="address" type="text">
</div>
</div>
On click event will get the form value and The final JSON object will look like,
{
"info": [
{
"Name": "string 1",
"email": "this",
"Address": "that"
},
{
"Name": "string 2",
"email": "this",
"Address": "that"
}
]
}
I tried to getting value from each of the input in different field.
var nameInput = document.getElementsByClassName("name"),
names = [].map.call(nameInput, function(input) {
return input.value;
});
But How do I add email and address field in object and map into array,
namehave you tried getting the values fromid tag?