DanWebb
8/28/2015 - 11:22 AM

Make key/value pairs from form elements based on name and value attributes

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;
});