Skip to content

Instantly share code, notes, and snippets.

View zipang's full-sized avatar
🏠
Working from home

Christophe Desguez zipang

🏠
Working from home
  • EIDOLON LABS
  • France
View GitHub Profile
@zipang
zipang / formData.js
Last active June 29, 2017 07:02
Serialize form data into a usable JS object(jQuery plugin)
/**
* jQuery plugin to convert form fields to a plain JS Object
* @usage var contactForm = $("form.contact").formData();
* @returns {'fieldName': 'fieldValue', (...)}
*/
$.fn.formData = function() {
var data = {},
keyValues = this.serializeArray();
$.each(keyValues, function() {
var field = this.name, val = this.value;