{"id":3854,"date":"2009-09-04T15:52:11","date_gmt":"2009-09-04T22:52:11","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3854"},"modified":"2009-09-06T13:47:03","modified_gmt":"2009-09-06T20:47:03","slug":"serialize-form-to-json","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/jquery\/serialize-form-to-json\/","title":{"rendered":"Serialize Form to JSON"},"content":{"rendered":"
$.fn.serializeObject = function()\r\n{\r\n   var o = {};\r\n   var a = this.serializeArray();\r\n   $.each(a, function() {\r\n       if (o[this.name]) {\r\n           if (!o[this.name].push) {\r\n               o[this.name] = [o[this.name]];\r\n           }\r\n           o[this.name].push(this.value || '');\r\n       } else {\r\n           o[this.name] = this.value || '';\r\n       }\r\n   });\r\n   return o;\r\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

$.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ”); } else { o[this.name] = this.value || ”; } }); return o; };<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3245,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":8258,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/fix-select-dropdown-cutoff-in-ie-7\/","url_meta":{"origin":3854,"position":0},"title":"Fix Select Dropdown Cutoff in IE 7","date":"January 6, 2011","format":false,"excerpt":"Run (at least the \"Usage\" part below) after you've loaded jQuery and either at the end of the page or in a DOM ready statement. Note that this fix does create a clone of the select, which will submit itself with the form data, but the name value has been\u2026","rel":"","context":"With 7 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3361,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/setclear-default-input-value\/","url_meta":{"origin":3854,"position":1},"title":"Set\/Clear Default Input Value","date":"August 11, 2009","format":false,"excerpt":"$('.default-value').each(function() { var default_value = this.value; $(this).focus(function(){ if(this.value == default_value) { this.value = ''; } }); $(this).blur(function(){ if(this.value == '') { this.value = default_value; } }); });","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3812,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/clear-field-on-focus\/","url_meta":{"origin":3854,"position":2},"title":"Clear Field on Focus","date":"September 4, 2009","format":false,"excerpt":"Replace \"value\" with the default value. If the field is selected, the default value will go away. If the user has previously changed the field value, it'll be left alone. Alternatively, use onfocus=\"this.value='';\" to always clear the field.","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":15825,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/async-script-loader-with-callback\/","url_meta":{"origin":3854,"position":3},"title":"Async Script Loader with Callback","date":"January 3, 2012","format":false,"excerpt":"var Loader = function () { } Loader.prototype = { require: function (scripts, callback) { this.loadCount = 0; this.totalRequired = scripts.length; this.callback = callback; for (var i = 0; i < scripts.length; i++) { this.writeScript(scripts[i]); } }, loaded: function (evt) { this.loadCount++; if (this.loadCount == this.totalRequired && typeof this.callback ==\u2026","rel":"","context":"With 15 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8315,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/javascript-md5\/","url_meta":{"origin":3854,"position":4},"title":"JavaScript MD5","date":"January 15, 2011","format":false,"excerpt":"var MD5 = function (string) { function RotateLeft(lValue, iShiftBits) { return (lValue>(32-iShiftBits)); } function AddUnsigned(lX,lY) { var lX4,lY4,lX8,lY8,lResult; lX8 = (lX & 0x80000000); lY8 = (lY & 0x80000000); lX4 = (lX & 0x40000000); lY4 = (lY & 0x40000000); lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF); if (lX4 & lY4) {\u2026","rel":"","context":"With 22 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17603,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/draggable-without-jquery-ui\/","url_meta":{"origin":3854,"position":5},"title":"Draggable without jQuery UI","date":"July 27, 2012","format":false,"excerpt":"It doesn't have all the fancy callbacks and options, but hey, it makes things draggable (and with a specified handle optionally). (function($) { $.fn.drags = function(opt) { opt = $.extend({handle:\"\",cursor:\"move\"}, opt); if(opt.handle === \"\") { var $el = this; } else { var $el = this.find(opt.handle); } return $el.css('cursor', opt.cursor).on(\"mousedown\",\u2026","rel":"","context":"With 88 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3854"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3854"}],"version-history":[{"count":2,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3854\/revisions"}],"predecessor-version":[{"id":3901,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3854\/revisions\/3901"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3245"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3854"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}