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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:54+00:00 2026-06-06T17:47:54+00:00

I am trying to insert data from a database into a textarea. I can’t

  • 0

I am trying to insert data from a database into a textarea. I can’t figure out how to make new lines though. I am using jquery’s val() function to set the textarea content. I put \n but it just shows up in the textarea instead of making a newline. I have also tried \r\n with the same result.

UPDATE

Ok, I noticed if I just hardcode a string with \n in the val() function that it works. So the problem must be somewhere with the string I am returning via ajax from php. I am using $.ajax to call PHP which gets the value from mysql. Any ideas on what is going wrong?

HTML

<textarea id='topContent' class='divContent' rows='8'></textarea>

JAVASCRIPT

<script>
$('#dialogDiv').on('submit', '#insertMacroForm', function(){
    $.ajax({
        url: 'index.php',
        data: 'request=loadMacro2&id='+$('#macroSelection').val(),
        success: function(msg){
            $('#topContent').val(msg);
        }
    });
    return false;
});
</script>

PHP

<?php
$query = 'SELECT * FROM POEMACRO WHERE POEID=' . db2_escape_string($_GET['id']);
$result = db2_exec($conn, $query) or die(db2_stmt_errormsg());
while($row = db2_fetch_assoc($result)){
    print $row['POEMACRO'];
}
?>
  • 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-06T17:47:56+00:00Added an answer on June 6, 2026 at 5:47 pm
    $('textarea').val('line1\nline2')
    

    This works fine.
    You need to use \n in your JavaScript string.
    If this string is formed in PHP on server, you may need something like json_encode() to format the string in JavaScript format.

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

Sidebar

Related Questions

I'm trying to insert some data from a proprietary JSON database into MongoDB for
I am trying to figure out how to retrieve data from a MySQL database
i am trying to insert data from excel sheet into database in java. for
I'm new to ASP. I am trying to insert data from an asp:textbox into
The data I am trying to insert is from a database, and while inserting
I am trying to select data from two tables and insert it into another
I am trying to insert data from a csv file into mysql using BigDump.
I am trying to insert a data into SQLite database using Python. INSERT INTO
I'm trying to insert a data into oracle database(version 11g xe).But when i'm trying
I'm getting this error when trying to insert data from a form into a

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.