Skip to content

Instantly share code, notes, and snippets.

@horitaku1124
Last active December 16, 2015 08:18
Show Gist options
  • Save horitaku1124/5404429 to your computer and use it in GitHub Desktop.
Save horitaku1124/5404429 to your computer and use it in GitHub Desktop.
Formにデータを入れるためのjs
var list = document.getElementsByTagName("input");
var kv = {};
for(var i = 0;i < list.length;i++) {
var name = list[i].getAttribute("name")
kv[name] = "";
}
var json = JSON.stringify(kv).replace(/","/g,"\"\n ,\"").replace(/^\{/,"{\n ").replace(/\}$/, "\n}");
// データを入れる
var data = JSON.parse(json);
for(var name in data) {
var val = data[name];
var elm = document.getElementsByName(name);
if(elm.length > 0) {
elm[0].value = val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment