Skip to content

Instantly share code, notes, and snippets.

@CezaryDanielNowak
Last active December 17, 2015 03:59
Show Gist options
  • Save CezaryDanielNowak/5547283 to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/5547283 to your computer and use it in GitHub Desktop.
jQuery.fn.loadSerializedData = function(data)
{
var dataObj = {},
keyValPair;
data = data.split('&');
for (var i = 0, length = data.length; i < length; i++) {
keyValPair = data[i].split('=');
dataObj[decodeURIComponent(keyValPair[0])] = decodeURIComponent(keyValPair[1]);
}
// Loop thru form and assign each HTML tag the appropriate value
$(this).find(':input').each(function() {
if (dataObj[$(this).attr('name')])
$(this).val(dataObj[$(this).attr('name')]);
});
};
//select your form in console first
$($0).loadSerializedData("output of form.serialize() function");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment