I would like to create a JSON string using multiple input fiels with same cla. Allow me to show you my HTML for explanation
<div>
Email:<input title="QA" type="text" class="email">
Name: <input type="text" class="name">
</div>
<div>
Email:<input title="DEV" type="text" class="email">
Name: <input type="text" class="name">
</div>
<div>
Email:<input title="PROD" type="text" class="email">
Name: <input type="text" class="name">
</div>
Currently my JavaScript is as follows:
var ServerUser = [];
$("input[class=email]").each(function() {
var id = $(this).attr("title");
var email = $(this).val();
tmp = {};
tmp['id '] = id;
tmp['email '] = email;
ServerUser.push(tmp);
});
However what it produces the following result
[{title: QA, email: '[email protected]'}, {title: PROD, email: '[email protected]'},{title: DEV, email: '[email protected]'}]
What I WOULD like to do is as follows
[{title: QA, email: '[email protected]', name: 'Paul'}, {title: PROD, email: '[email protected]', name: 'Mark'},{title: DEV, email: '[email protected]', name: 'Mike'}]
Where the name value would come from the respective Name input field.
How do I approach this problem? Thank you for your help and reading this.
Regards.
titleandemailwhen you are clearly usingTaskIDandClientEmailin your js? I assume you simplified it a little. You'll need to get thenameinside of the same each that is getting theemailandtitle.