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

  • SEARCH
  • Home
  • 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 6952957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:24:59+00:00 2026-05-27T14:24:59+00:00

I have the following HTML code, which essentially copies a textarea box, including its

  • 0

I have the following HTML code, which essentially copies a textarea box, including its text.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Test Page</title>
        <script type="text/javascript">
            function copyTextarea() {
                var originalTextbox = document.getElementById('originalTextarea');
                var copiedTextboxSpan = document.getElementById('copiedTextareaSpan');

                var text = originalTextbox.value;

                copiedTextboxSpan.innerHTML = '<textarea name="myNewTextarea" rows="5" cols="50"></textarea>';

                var newTextbox = document.getElementsByName('myNewTextarea')[0];
                newTextbox.innerHTML = text;
            }
        </script>
    </head>
    <body>
        Enter your text:
        <br />
        <textarea id="originalTextarea" rows="5" cols="50"></textarea>
        <br />
        <input type="button" value="Copy Textarea" onclick="copyTextarea()" />
        <br />
        Copied text:
        <br />
        <span id="copiedTextareaSpan"></span>
    </body>
</html>

This is a very simplified version of HTML I have, so please don’t suggest huge changes. I need to create the textarea box and set its text separately, etc.

This code seems simple and works fine, except when it comes to newline characters. For some reason, Internet Explorer (IE) always converts newlines into a single space. Stranger still, this was not happening locally on my Tomcat server, but crept up when I deployed to the test server. But on the test server, it is working fine in Chrome, Firefox, etc.

Does anyone know what might be happening? I don’t know too much about JavaScript, but I think it’s the browser that executes the code. But if that is true, why does IE have no problems locally but has a problem on the test server?

  • 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-27T14:25:00+00:00Added an answer on May 27, 2026 at 2:25 pm

    Try creating actual DOM objects:

    newTextarea = document.createElement('textarea');
    newTextarea.setAttribute('name', 'myNewTextarea');
    newTextarea.setAttribute('rows', '5');
    newTextarea.setAttribute('cols', '50');
    
    copiedTextboxSpan.appendChild(newTextarea);
    
    var newTextbox = document.getElementsByName('myNewTextarea')[0];
    newTextbox.value = text;
    

    Also, use value instead of innerHTML when dealing with a textarea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have uploaded the following simple HTML code to http://losthobbit.net/temp/anchor.html <!DOCTYPE HTML PUBLIC -//W3C//DTD
I have the following HTML/CSS code in which a line of text is shown
I have following 2 files as below: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
I have the following code which loads and html file into a webview -
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
I have the following html code: <mytag> Just Some Text </mytag> And I have
i have a script which generate the following HTML code : <table class=table> <tr><td
I have following HTML code. writer input field is text filed. but I want
I have the following HTML code (which is placed within several files), which inserts
I have the following HTML code: <td> <input type=text size=40 value= name=related_image id=related_image> <input

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.