How do I convert some elements of my form to a JSON?
I want the JSON data not based on "name": "value"
, but "value1": "value2"
.
Where "value1" is the input element 1 and "value2" is the input element 2.
And what if I want to add an object to the previous JSON data? For example,
dataBefore = {"key": "1"};
dataAfter = {"key": "1", "data": "2"};
The code have i tried,
var person = {};
var key = $('#com-key2').val();
person[key] = $('#com-value2').val();
And the UI like this, form example
Note: ID of all input element is same
How to do that? Sorry if the language is hard to understand