Skip to content

Instantly share code, notes, and snippets.

@isc30
Created July 20, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isc30/1107ccf59fac80e9dd31532a33b2c1c2 to your computer and use it in GitHub Desktop.
Save isc30/1107ccf59fac80e9dd31532a33b2c1c2 to your computer and use it in GitHub Desktop.
function serializeForm(form)
{
var elems = form[0].elements;
var serialized = [], i, len = elems.length, str = "";
for (i = 0; i < len; i += 1)
{
var element = elems[i];
var type = element.type;
var name = element.name;
var value = element.value;
switch (type)
{
case "radio":
case "checkbox":
if (!element.checked)
{
break;
}
case "hidden":
case "text":
case "textarea":
case "select-one":
str = name + "=" + value;
if (name.toString() != "")
{
serialized.push(str);
}
break;
default:
break;
}
}
return serialized.join("&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment