Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.fn.serializeObject = function () {
  2.         var o = {};
  3.         $(this).find("input[type='hidden'], input[type='text'], input[type='password'], input.k-textbox, input[type='checkbox']:checked, input[type='radio']:checked, select, textarea").each(function () {
  4.             if ($(this).attr("type") == "hidden") { //if checkbox is checked do not take the hidden field
  5.                 var $parent = $(this).parent();
  6.                 var $chb = $parent.find("input[type='checkbox'][name='" + this.name.replace(/\[/g, "\[").replace(/\]/g, "\]") + "']");
  7.                 if ($chb != null) {
  8.                     if ($chb.prop("checked")) return;
  9.                 }
  10.             }
  11.             if (this.name === null || this.name === undefined || this.name === "")
  12.                 return;
  13.             var elemValue;
  14.             if ($(this).is("select")) {
  15.                 elemValue = $(this).find("option:selected").val();
  16.             } else {
  17.                 elemValue = this.value;
  18.             }
  19.             if (o[this.name] !== undefined) {
  20.                 if (!o[this.name].push) {
  21.                     o[this.name] = [o[this.name]];
  22.                 }
  23.                 o[this.name].push(elemValue || "");
  24.             } else {
  25.                 o[this.name] = elemValue || "";
  26.             }
  27.         });
  28.         return o;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement