Created
May 6, 2019 14:13
-
-
Save SethVandebrooke/d6150b85068f617825146c2f3f290fe4 to your computer and use it in GitHub Desktop.
Generate Form DOM Element
This file contains hidden or 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 generateFormDOMElement(name, action, method, fields) { | |
var form = document.createElement("form"); | |
form.name = name; | |
form.action = action; | |
form.method = method; | |
for (var name in fields) { | |
var attributes = fields[name]; | |
var field = document.createElement("input"); | |
field.id = name; | |
field.name = name; | |
for (var attr in attributes) { | |
field[attr] = attributes[attr]; | |
} | |
form.appendChild(field); | |
} | |
return form; | |
} | |
/* | |
var form = generateFormDOMElement("register","/register.php","POST", { | |
fullName: {type: "text", required: "true"}, | |
email: {type: "email", required: "true"}, | |
password: {type: "password", required: "true"}, | |
confirmPassword: {type: "password", required: "true"}, | |
dateOfBirth: {type: "date", required: "true"} | |
}); | |
body.appendChild(form); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment