Skip to content

Instantly share code, notes, and snippets.

@jmahc
Last active September 16, 2015 21:53
Show Gist options
  • Save jmahc/fa3c8f6a58a6cc285814 to your computer and use it in GitHub Desktop.
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.
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