Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:27+00:00 2026-05-26T11:09:27+00:00

Look at the below code, this JavaScript is used to take a string (in

  • 0

Look at the below code, this JavaScript is used to take a string (in a language other than English) and convert it into English.

<script type="text/javascript">
    google.load("language", "1");

    function initialize() {
       var content = document.getElementById('translation');
       // Setting the text in the div.
       content.innerHTML = '<div id="text">HELLO WORLD<\/div>
                            <div id="translation"/>';

       // Grabbing the text to translate
       var text = document.getElementById("text").innerHTML;

       // Translate from Spanish to English, and have the callback of
       // the request put the resulting translation in the
       // "translation" div.  Note: by putting in an empty string for
       // the source language ('es') then the translation will
       // auto-detect the source language.

       google.language.translate(text, '', 'en', function(result) {
       var translated = document.getElementById("translation");
       if (result.translation) {
           translated.innerHTML = result.translation;
       }
     });
   }

   google.setOnLoadCallback(initialize);

</script>

I want that the string “HELLO WORLD” must be entered by user at run time in a text field and then that string is passed to the div id text. So is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:09:28+00:00Added an answer on May 26, 2026 at 11:09 am

    Hope you are referring to the document below:

    http://code.google.com/apis/language/translate/v1/getting_started.html

    Please refer to the section “Getting Started” where it says about “Signing up for an API key”. This needs to be done before you could implement the code in your page.

    Once done, make the modification to the script file which you include in the html page with your key.

    Here, replace your key with “MY_KEY_STRING” in the bottom code and get started.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google AJAX Language API Sample</title>
        <script src="https://www.google.com/jsapi?key=MY_KEY_STRING"></script>
        <script type="text/javascript">
    
        google.load("language", "1");
    
        function initialize() {
        //Show the translate button
        document.getElementById("translateButton").style.display = "";
         }
        google.setOnLoadCallback(initialize);
        function translate() {
        var text = document.getElementById("fromText").value;
            google.language.translate(text, 'es', 'en', function(result) {
            var translated = document.getElementById("toText");
            if (result.translation) {
              translated.innerHTML = result.translation;
            }
          });
        }
        </script>
      </head>
      <body style="font-family: Arial;border: 0 none;">
        From:<input type="text" id="fromText"/>
        To:<span id="toText"></span>
        <input type="button" value="Translate" onclick="translate()" style="display: none;" id="translateButton">
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look please below this codes throw me : FormatException was unhandled by user code
Please have a look at the code below: import string from collections import defaultdict
Hey everyone, take a look at the code below and appreciate how messy the
I have a javascript function which get datagrid's header into THEAD tags. This code
Alright, to start with let's look at some code: <html> <body> <script type=text/javascript> function
Please have a look on the code below .. <div id=click_me>Save</div> <div id=blocks_sortable> <div
Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
If you look at the code inside the #top_cat and #high_hat sections below, it's
I have a large number of csv files that look like this below: xxxxxxxx
Please take a look at the html listed below and let me know why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.