Skip to content

Instantly share code, notes, and snippets.

@DanWebb
Created August 28, 2015 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanWebb/9e53b7ff283dd412a5bd to your computer and use it in GitHub Desktop.
Save DanWebb/9e53b7ff283dd412a5bd to your computer and use it in GitHub Desktop.
Make key/value pairs from form elements based on name and value attributes
var obj = {};
$('form').find('input, select, textarea').each(function() {
obj[this.name] = this.value;
});
// Or create an object based on a specific group of form elements
var address = {};
$('form').find('[name^="address"]').each(function() {
address[this.name.replace('address[','').replace(']','')] = this.value;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment