Last active
December 16, 2015 08:18
-
-
Save horitaku1124/5404429 to your computer and use it in GitHub Desktop.
Formにデータを入れるための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
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