How To Add A Simple Onselect Alert In Google Translate Api?

Discussion in 'JavaScript' started by fwcswebguy, Jan 24, 2013.

  1. #1
    Here is the code for Google Translate API
    <div id="google_translate_element"></div>
    <script type="text/javascript">
        function googleTranslateElementInit() {
          new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'es,en', layout: google.translate.TranslateElement.FloatPosition.TOP_RIGHT}, 'google_translate_element');
        }
     
    </script>
    <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    Code (markup):
    Since it does not translate phrases very well, my superiors want a simple alert message to pop-up in spanish letting them know it is translated by a computer. I'm not that great with javascript and I have done this before using onselect when the select statement is in html but I can't get this to work with Googles API. I simply need it to alert when Spanish is selected.
    I came up with a simple workaround using an input button but the problem is that it resets the language if you click a new page. Any help would be awesome.

    FYI, I don't need it to translate to pop-up alert, that can just be hardcoded.
     
    fwcswebguy, Jan 24, 2013 IP