Note that there are some explanatory texts on larger screens.

plurals
  1. POMicrosoft translator AJAX API, dropdown to change languageTo and languageFrom?
    primarykey
    data
    text
    <p>I am trying to write a translator box for my website. So far, I've been able to get working code from a tutorial:</p> <pre><code>&lt;input id="ori" type="text" /&gt; &lt;button onclick="translate();"&gt;Translate&lt;/button&gt; &lt;div id="trans"&gt;&lt;/div&gt; &lt;script&gt; var languageFrom = "en"; var languageTo = "fr"; function translate() { document.getElementById('trans').innerHTML="Translating... please wait"; var text= document.getElementById('ori').value; window.mycallback = function(response) { document.getElementById('trans').innerHTML=response; } var s = document.createElement("script"); s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=mycallback&amp;appId=&lt;MY-APP-ID&gt;&amp;from=" + languageFrom + "&amp;to=" + languageTo + "&amp;text=" + text; document.getElementsByTagName("head")[0].appendChild(s); } &lt;/script&gt; </code></pre> <p>(Script it from here: <a href="http://wizardsoweb.com/microsoftbing-translator-ajax-example/2011/05/?wpmp_switcher=desktop" rel="nofollow noreferrer">http://wizardsoweb.com/microsoftbing-translator-ajax-example/2011/05/?wpmp_switcher=desktop</a>)</p> <p>Basically, once I fill in my APPID, it will translate the text in the <code>ori</code> text box to French. Of course, this all works fine, but here's what I'm trying to do:</p> <p>I want there to be two drop down menus. One will populate the <code>languageFrom</code> variable with a specified language, and another drop down menu which will populate the <code>languageTo</code> variable with a specified language. </p> <p>I've already posted about this matter in a different post: <a href="https://stackoverflow.com/questions/8022924/update-script-vars-with-value-from-drop-down">Update script var&#39;s with value from drop down?</a>. That way, when you select a value from the drop down menu, it populates the variable. I have a working example of this on jsFiddle:</p> <p><a href="http://jsfiddle.net/charlescarver/hk2bJ/1/" rel="nofollow noreferrer">http://jsfiddle.net/charlescarver/hk2bJ/1/</a></p> <p>(I included my API key so it's easier to work on)</p> <p><strong>SO</strong>, I think the problem with this is that the script which controls the translation is loaded when the variables are empty, and then doesn't update when a drop down option is selected.</p> <p>I think this can be fixed by calling the script when the button is clicked, instead of when the page is loaded. How can this be accomplished? The Microsoft support is poorly documented and I can't find a solution there or on google. Here's a link to the API documentation: <a href="http://msdn.microsoft.com/en-us/library/ff512385.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ff512385.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload