Hello, im trying to pass two parameters to a function, "i" being an int value and "map" being an object. I'm using eval to inform Javascript that I am passing objects, however im getting the error "missing ] after element list".
I'm kinda new to this so I'm not 100% sure if this is the right way of doing things... but ya.. hopefully i'm on the right track.
...
optionsControlDiv.innerHTML += '<input type="checkbox" onclick="toggleLayer('+eval(i)+","+eval(map)+')"'+c+' />'+this.opts[i]+'<br>';
console.log('<input type="checkbox" onclick="toggleLayer('+eval(i)+","+eval(map)+')"'+c+' />'+this.opts[i]+'<br>');
// OUTPUT:
// <input type="checkbox" onclick="toggleLayer(0,[object Object])" />Wiki<br>
// <input type="checkbox" onclick="toggleLayer(1,[object Object])" />webcams<br>
// <input type="checkbox" onclick="toggleLayer(2,[object Object])" />Photos<br>
// ERROR:
// missing ] after element list
// [Break on this error] toggleLayer(0,[object Object])
...
// The function
function toggleLayer(i,map) {
//console.log(i);
if (layers[i].Visible) {
layers[i].hide();
} else {
if(layers[i].Added) {
layers[i].show();
} else {
map.addOverlay(layers[i]);
layers[i].Added = true;
}
}
layers[i].Visible = !layers[i].Visible;
}