Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created August 17, 2011 20:45
Show Gist options
  • Save danhigham/1152569 to your computer and use it in GitHub Desktop.
Save danhigham/1152569 to your computer and use it in GitHub Desktop.
Serializes form elements in to a javascript object
$ = jQuery
$.extend $.fn,
serializeObject: () ->
e = $(this)
a = e.serializeArray()
o = {}
$.each a, ->
if o[this.name] != undefined
o[this.name] = [o[this.name]] if !o[this.name].push
o[this.name].push(this.value || '')
else
o[this.name] = this.value || ''
return o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment