Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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