Created
August 28, 2015 11:22
-
-
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
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
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