Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
Line break issue with textarea

I have a project that saves user inputs from HTML form and get saved in MySQL db.

For example, I have this function

function funcGetRecordDetails(editID){
    $('#hiddenID').val(editID);
    var action = "get_record_teams";

    $.ajax({
      url : "teams_post.php",
      type : 'post' ,
      data : { editID : editID,
               action: action } ,
      success : function(data, status){

        var edit_data = JSON.parse(data);

        $('#mdl_update_team_order').val(edit_data.order_no);
        $('#mdl_update_team_team').val(edit_data.team);
        $('#mdl_update_team_names').val(edit_data.name);

      }
    });

  }

In my case edit_data.name will have line breaks. But mdl_update_team_names textarea is NOT displaying the line breaks properly.

For example, the data in DB is saved as a\nb and that is exactly how it will be shown in the textarea.

For testing purpose, I changed it to $('#mdl_update_team_names').val('a\nb'); and the textarea IS displaying line breaks properly which is

a
b

Any idea how to display the line breaks properly from the DB?

Edit 1

When I do this, it works

var edit_data = JSON.parse('{"id":41,"snow_inc":"XXX","order_no":0,"team":"44","name":"a\\nb","update_by":"XXX","update_date_time":"2021-09-08 14:12:01"}')

But when I do this, it doesnt work.

var edit_data = JSON.parse(data)

But the response I'm getting is the same, which is

{"id":41,"snow_inc":"XXX","order_no":0,"team":"44","name":"a\\nb","update_by":"XXX","update_date_time":"2021-09-08 14:12:01"}

Tried this as well var edit_data = JSON.parse(data.toString()); with the same results.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!