Created
August 12, 2016 22:34
-
-
Save rdev5/f3111f88ea5e6443ddaad2a820ac2b05 to your computer and use it in GitHub Desktop.
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
var createForm = function(action, fields) { | |
function isObject(val) { | |
if (val === null) { return false;} | |
return ( (typeof val === 'function') || (typeof val === 'object') ); | |
} | |
if (!isObject(fields)) | |
return; | |
// Create form | |
var f = document.createElement('form'); | |
f.setAttribute('action', action); | |
f.setAttribute('method', 'post'); | |
f.setAttribute('hidden', 'true'); | |
// Append form fields | |
for (var k in fields) | |
{ | |
var field = document.createElement('input'); | |
field.setAttribute('type', 'hidden'); | |
field.setAttribute('name', k); | |
field.setAttribute('value', fields[k]); | |
f.appendChild(field); | |
} | |
// Add form fields | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment