Created
April 3, 2018 17:07
-
-
Save cedeber/8b00d6980ff31152b06207b0160afbe4 to your computer and use it in GitHub Desktop.
Serialize Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serialize(form) { | |
const inputs = form.querySelectorAll("input"); | |
const fields = {}; | |
for (const input of inputs) { | |
if (input.name && !input.disabled && input.type !== "file" && input.type !== "reset" && input.type !== "submit" && input.type !== "button") { | |
if ((input.type !== "checkbox" && input.type !== "radio") || input.checked) { | |
fields[input.name] = input.value; | |
} | |
} | |
} | |
return fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment