Created
January 27, 2015 13:38
-
-
Save tokuhirom/cb8d74b57f95c5868a4a to your computer and use it in GitHub Desktop.
fillinform.js
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 () { | |
// public domain. buggy. | |
"use strict" | |
var elems = document.getElementsByClassName("fillinform"); | |
var query = parseQuery(); | |
for (var i = 0, l = elems.length; i < l; i++) { | |
var it = elems[i]; | |
Object.keys(query).forEach(function (key) { | |
var input = it.querySelector("input[name=" + key + "]"); | |
if (input.type == "checkbox") { | |
input.checked = true; | |
} else { | |
input.value = query[key]; | |
} | |
}); | |
} | |
function parseQuery() { | |
var query = window.location.search.substring(1); | |
var vars = query.split('&'); | |
var retval = { }; | |
for (var i = 0; i < vars.length; i++) { | |
var pair = vars[i].split('='); | |
var key = decodeURIComponent(pair[0]); | |
var val = decodeURIComponent(pair[1]); | |
retval[key] = val; | |
} | |
return retval; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment