I wanna set HTML form elements value using json object by jquery.
I have done adding the values by serializeArray() in an HTML localstorage.
var formData = $('#page-2').serializeArray();
formData.forEach(function(field){
var dataDInfo = {};
if($.inArray(field.name, propertyDList) >= 0){
if($('#'+field.name).data('displayName')){
dataDInfo['present'] = field.value;
dataDInfo[displayName] = $('#'+field.name).data('displayName');
list.propertyDCategory[field.name] = dataDInfo;
} else {`enter code here`
list.propertyDCategory[field.name] = field.value;
}
}
});
now i am having all values in json object say list.
I am getting all data by using
var lists = JSON.parse(localStorage.getItem('list'));
eg: json
{
aa:ab,
bb:{
cc:cb,
dd:db
},
ee:eb
}
Now i want to write a edit and update function and fill all the elements value by using json data based on json data field (name of HTML element is equal to json data field) after that i wanna update the local storage list.
Note : html form contain input, radio button, check list, select types of elements.
elements are changing based on select element.
Can anyone help me to write the code?
Thanks.