Skip to content

Instantly share code, notes, and snippets.

@DanWebb
Created August 28, 2015 11:22
Show Gist options
  • Select an option

  • Save DanWebb/9e53b7ff283dd412a5bd to your computer and use it in GitHub Desktop.

Select an option

Save DanWebb/9e53b7ff283dd412a5bd to your computer and use it in GitHub Desktop.

Revisions

  1. DanWebb created this gist Aug 28, 2015.
    10 changes: 10 additions & 0 deletions form_obj.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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;
    });