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 8972631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:15:43+00:00 2026-06-15T18:15:43+00:00

SOLVED The problem is solved in a tricky way. The answer is posted below

  • 0

SOLVED

The problem is solved in a tricky way. The answer is posted below.


I have a textarea control with white-space: pre; style, which works perfectly well while editing new stuff, storing it into a database (intact, with \r\n), and displaying as an inline part of html page (inside a div with the same style).

The problem occurs when I try to edit such text in a popup dialog with the same textarea feeded from AJAX response. I’m trying to assign received text into the textarea by means of jQuery:

$('#textfield').html(text);

Actually the whole dialog with filled in textarea is received in the response.

Unfortunately, this html-setter removes leading linebreak. Is there a way to eliminate such inconsistent behaviour? Linebreaks which occur further in content are presaved normally.

Example of html code, received from the server:

<textarea id="newtext" cols="60" rows="3" style="white-space:pre;">
Text with line break at its start.
More line break</textarea>

After placing the code by means of html into container, I got exactly this:

<textarea id="newtext" cols="60" rows="3" style="white-space:pre;">Text with line break at its start.
More line break</textarea>

P.S. More code added from the context, though I don’t think this may help somehow:

JavaScript:

var d = $('#dialog');

console.log(msg); // correct data
console.log('==============');

d.html(msg).css({position: "absolute", top: (pos.top + height) + "px", left: (pos.left + width) + "px"});

console.log(d.html()); // corrupted data

d.show();
$('#newtext').focus();

HTML with container:

<div id="dialog" class="popup">
</div>

UPDATE:

As @Pointy suggested, it’s indeed not jQuery’s issue. I replaced the html-setter to the plain old:

document.getElementById("dialog").innerHTML = msg;

and got the same problem. Browser is Chrome. Can’t test other browsers right now.

  • 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-06-15T18:15:44+00:00Added an answer on June 15, 2026 at 6:15 pm

    I’ve got a workaround, very simple one. Into the original HTML code of the textarea:

    <textarea id="newtext" cols="60" rows="3" style="white-space:pre;"><?php echo $templateVariablePlaceholder; ?></textarea>
    

    I added a linebreak after opening tag:

    <textarea id="newtext" cols="60" rows="3" style="white-space:pre;">
    <?php echo $templateVariablePlaceholder; ?></textarea>
    

    Now it works, as expected.

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

Sidebar

Related Questions

Problem solved, see below Question I'm working in Flex Builder 3 and I have
[EDIT: Problem solved. Please see my answer below.] In my app I call the
I have sort of a tricky problem I'm attempting to solve. First of all,
I solved Problem 10 of Project Euler with the following code, which works through
Issue is SOLVED: Problem is that it is a pre-compiled web page project and
(Problem solved now, see answers below) Hello, in my app I am trying to
Updated Problem solved, I have some design problem here. The directory looks like that:
I've stuck with one quite tricky problem. I have list of products from different
I can't see this in the docs, but I presume it's a solved problem.
Solved: The problem was a virus or something similar that was hijacking the port.

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.