I've edited the code you provided to do what you desire. Please note that the code below will store the translation in a global variable (i.e., accessible to the entire application). The updated variable will not be available until after the translation returns (i.e., there could be a noticeable lag, so you can't use the variable until after translateResult runs). And the variable will be overwritten with each subsequent translation request.
Jeremy R. Geerdes Effective website design & development Des Moines, IA For more information or a project quote: http://jgeerdes.home.mchsi.com [EMAIL PROTECTED] Unless otherwise noted, any price quotes contained within this communication are given in US dollars. If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church! On Oct 7, 2008, at 10:28 PM, Henry wrote: > > Hi, > I was wondering if anyone knew how to use google.language.translate > and store the result as a javascript variable. > As in the example given in the documentation: > > function submitChange() { > var text = document.getElementById('source').value; > var dst = document.getElementById('dst').value; > var src = "en"; > var result = document.getElementById("results_body"); > google.language.translate(text, src, dst, translateResult); > return false; > } > > function translateResult(result) { > var resultBody = document.getElementById("results_body"); > if (result.translation) { > // resultBody.innerHTML = result.translation; // we won't > put the translation on the page window.myJSVar = result.translation; > > } else { > // resultBody.innerHTML = '<span style="color:red">Error > Translating</span>'; // again, not putting the error on the page window.myJSVar = 'Error translating'; > > } > } > > I would like to store the translated text as a new variable such as: > translatedText > > Thanks, > Henry > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google AJAX API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-AJAX-Search-API?hl=en -~----------~----~----~----~------~----~------~--~---
