Last active
September 16, 2015 21:53
-
-
Save jmahc/fa3c8f6a58a6cc285814 to your computer and use it in GitHub Desktop.
Takes a query string with multiple parameters of the same name ("word1", "word2", etc.) and inserts these values into a textbox.
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 getQueryParams = function () { | |
var params = []; | |
var query = window.location.search; | |
query = query.slice(1, query.length); | |
var nv = query.split('&'); | |
for (var i = 0; i < nv.length; i++) { | |
var q = nv[i].split('='); | |
params[q[0]] = q[1]; | |
} | |
return params; | |
}; | |
var p = getQueryParams(); | |
var word = "word"; | |
var wordValues = ""; | |
var x = 1; | |
var y = 0; | |
var array = []; | |
getWordValues(p); | |
function getWordValues(p) { | |
for (var item in p) { | |
var index = word + x; | |
array.push(p[index]); | |
x++; | |
} | |
var values = storeWordValues(array); | |
insertWord(values); | |
return; | |
} | |
function storeWordValues(array) { | |
for (var item in array) { | |
wordValues = wordValues + array[y] + ", "; | |
y++; | |
} | |
wordValues = wordValues.replace(/,\s*$/, ""); | |
return wordValues; | |
} | |
function insertWordValues(text) { | |
var TheTextBox = document.getElementById("target_textbox"); | |
TheTextBox.value = TheTextBox.value + text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment