I want to get the selected language from an embedded Google translate script in a dynamic php website.
I have inserted in the head
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'el', includedLanguages: "en,el"
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?
cb=googleTranslateElementInit"></script>
and in body:
<div style="text-align:center!important;" id="google_translate_element"></div>
and translate dropdown appears ok and does the job ok.
I want to detect the selection of the language, so I run some script depending on the selection.
So far the javascript that is executing correctly is:
<script type="text/javascript">
window.setInterval(function(){
lang = $("select.goog-te-combo option:selected").text();
alert(lang);
},7000);
</script>
that shows an alert window every 7 sec with the selected language text.
How do I change the above script so that is executed only on dropdown selection change?