Reputation: 63
Here's the code for the geochart map I'm trying to implement on my site:
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country'],
['Italy'],
['Germany'],
['France'],
['Turkey'],
['Indonesia']
]);
var options = {
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
google.visualization.events.addListener(chart, 'select', function() {
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var country = data.getValue(selectedItem.row, 0);
if (country = 'France') { alert ('ciao') };
}
});
};
Would I would like to achieve is that if a user selects a particular region (for example France) a Javascript function is called. Now, the variable country works correctly (if you press France it sets to France) but there must be something wrong with if (country=) because it carries the same action even if I select a country that isn't France.
Any help would be much appreciated.
Upvotes: 6
Views: 3905
Reputation: 785
You need to use equality operator ==
instead of assignment operator =
here:
if (country == 'France') { alert ('ciao') };
Otherwise, you are setting country equal to 'France' and the if
statement will always be true.
Upvotes: 3