Below is how I am capturing and saving the values of my web form to JSON, using the name attribute and values.
How can I repopulate the form from my captured JSON data in the same format using name and value. (context: I will stash the saved json, and call it later to repopulate said form)
My code to save the values as JSON:
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$(function() {
$('form#saveTemp').submit(function() {
alert(JSON.stringify($('form').serializeObject()));
return false;
});
});
A jsfiddle of it.