Geochart: running a function on 'select'

Here is the code for the geochart map that I am 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') }; } }); }; 

I would like to ensure that if the user selects a specific region (e.g. France), the javascript function is called. Now the country variable is working correctly (if you push France to France), but there must be something wrong with if (country =), because it performs the same action, even if I choose a country that is not France .

Any help would be greatly appreciated. thanks in advance

+6
source share
1 answer

You need to use the equality operator == instead of the assignment operator = here:

if (country == 'France') { alert ('ciao') };

Otherwise, you set the country to "France", and the if will always be true.

+2
source

All Articles