I have a .js file which looks something like this:
function regionmap () {
var width = 960,
height = 500,
centered;
var projection = d3.geo.albersUsa()
.scale(width)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.attr("id","svg");
var states = svg.append("g")
.attr("id", "states")
d3.json("readme.json", function(json) {
d3.select("svg").selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.on("click", clicked)
.append("title")
.text(function(d) { return d.properties.name; });
});
listofnames = new Array();
listofnames.push("Regions:");
function clicked (d) {
var regionname = d.properties.name;
var currentclass = d3.select(this).attr("id") ;
if (currentclass == "active") {
d3.select(this).attr("id", "nonactive");
} else {
d3.select(this).attr("id", "active");
}
var contains;
var index;
for (var i = 0; i < listofnames.length; i++) {
if (regionname != listofnames[i]) {
contains = false;
} else {
contains = true;
index = i;
break;
}
}
if (contains == false){
listofnames.push(regionname);
} else if(contains == true){
listofnames.splice(index,1);
}
var x=document.getElementById("demo");
x.innerHTML=listofnames;
}
function sendingvariable (){
window.location.href = "../php/fileregions.php?name=" + listofnames;
}
}
The thing is that when calling the function from html I first call the function regionmap on click ( onclick="regionmap()) which works good. However, I then need to call the function sendingvariable from the html, and I am not able. Any way to solve this?
}from line 4 and move it to the end of line 1. Then function a and b both work.window.b || (window.b = function () {});