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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:26:00+00:00 2026-05-21T18:26:00+00:00

To keep my code clean I am defaulting each of the elements of a

  • 0

To keep my code clean I am defaulting each of the elements of a form with jQuery.

i.e My form contains elements like this..

<input name="mobile" id="mobile" type="text" />

In my separate javascript file, I read data from MySQL, then use jQuery to set it, after the form is loaded..

$('#mobile').val('07845 887766');

this value is read from MySQL and I generate the code like this, in PHP..

echo "\n $('#mobile').val('".$user['mobile']."');";

This works fine, but the problem lies when there is a textarea field..

<textarea name="notes" id="notes" ></textarea>

echo "\n $('#notes').html('TEST');";

This works fine, but when I replace it with the data from a database, which can contain newlines, I get a javascript error.

echo "\n $('#notes').html('".$user['notes']."');";

This could produce this code (Actual values…)

$("#notes").html("INSERT INTO action    (
                    inputdate,
                )
                VALUES ()");

Which gives an error. “unterminated string literal”

  • 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-21T18:26:01+00:00Added an answer on May 21, 2026 at 6:26 pm

    unterminated string literal

    You’re getting this message because in Javascript you can’t span literal strings across multiple lines.

    What you need to do is replace newlines in $user['notes'] with the characters \r\n so all the string is on one line then the <textarea> input will correctly show each item on a new line.

    Let’s use json_encode to help us also escape any nasty characters which Javascript won’t like.

    // This will convert to be Javascript friendly. 
    // Output string will be enclosed in quotes " "
    $notes_str = json_encode($user['notes']);
    echo "\n $('#notes').html(" . $notes_str . ");";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep seeing code that does checks like this if (IsGood == false) {
I'm trying to keep my code clean and keep the number of files down.
In general, I don't like to keep code (BaseClasses or DataAccess Code) in the
I'm trying to learn about this feature of javascript I keep seeing in code,
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
In order to keep my code clean and organized, I split my classes up
Normally I love to keep my HTML code clean, semantic and free from either
I am trying to keep my code as secure/clean as possible. If I have
I am reading Clean Code and having trouble figuring out how to keep some
I have some code that invokes anonymous functions within a loop, something like this

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.