Skip to content

Instantly share code, notes, and snippets.

@rolfen
Last active June 27, 2017 19:45
Show Gist options
  • Save rolfen/cb53eda59174d71f00b8fd804bef82a6 to your computer and use it in GitHub Desktop.
Save rolfen/cb53eda59174d71f00b8fd804bef82a6 to your computer and use it in GitHub Desktop.
Serialize form to JSON - the simple way
// credit: https://codepen.io/gabrieleromanato/pen/LpLVeQ
function parseInputs( elements ) {
var obj = {};
for( var i = 0; i < elements.length; ++i ) {
var element = elements[i];
var name = element.name;
var value = element.value;
if( name ) {
obj[ name ] = value;
}
}
return ( obj );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment