Last active
December 17, 2015 03:59
-
-
Save CezaryDanielNowak/5547283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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