Created
January 9, 2014 18:07
-
-
Save sclarson/8338984 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
| function ConvertToFormAndSubmit(databag, url, inputName) { | |
| var index = 0; | |
| var form = document.createElement('form'); | |
| form.setAttribute("method", "post"); | |
| form.setAttribute("action", url); | |
| if (databag instanceof Array) { | |
| for (index = 0; index < databag.length; index++) { | |
| for (var prop in databag[index]) { | |
| if (databag[index].hasOwnProperty(prop)) { | |
| if (typeof(databag[index][prop]) != 'undefined' && databag[index][prop].length > 0) { | |
| var input = document.createElement('input'); | |
| input.setAttribute("type", "hidden"); | |
| input.setAttribute("name", inputName + "[" + index + "]." + prop); | |
| input.setAttribute("value", databag[index][prop]); | |
| form.appendChild(input); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| document.body.appendChild(form); | |
| form.submit(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment