I'm trying to dynamically generate an array and concatenate the results without turning the google maps function into strings.
Any suggestions on the best way to do this would be great.
Here is a snippet of my code:
function goCheck() { // find out what checkboxes in the form were selected
//set a few variables and arrays
var input = document.getElementsByTagName('input');
var checkboxCount = 0;
var selections = [];
var urlArray = [];
// 1st loop to get form checkbox selections
for (var i=0, length = input.length; i<length; i++) {
if (input[i].checked === true) {
s = input[i].value;
selections.push(s); // store values for checkbox selections in array
checkboxCount++; // keep track how many were checked
var url = "https://mywebsite.ca/" + s + ".txt";
urlArray.push(url); // store urls in array
}
}
console.log(checkboxCount); // number of boxes checked
console.log(selections); // array with the selections
console.log(urlArray); // an array with the json urls
// 2nd Loop - iterate over URL array and call function to get json object
var xmlhttp;
var myArr;
for (var i=0, length = urlArray.length; i<length; i++) {
xmlhttp = new XMLHttpRequest(); //
console.log(xmlhttp);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.response);
console.log(myArr);
console.log(myArr[selections[i]]);
console.log(myArr[selections[i]].length);
/* this is where I'm getting into trouble ----->
var arraySize = (myArr[selections[i]].length);
for(k=0; k<arraySize; k++) {
district = "new google.maps.LatLng("+myArr[selections[i]][0]+")";
polyLayer.push(district);
<----- */
}
}
};
xmlhttp.open("GET", urlArray[i], false);
xmlhttp.send();
}}