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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:35:56+00:00 2026-06-05T18:35:56+00:00

Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,

  • 0

Possible Duplicate:
Pass a PHP string to a Javascript variable (including escaping newlines)

Hy, so my problem is that i have a textarea which is generated with jquery, like this:

$var input = $('<textarea name="somename"></textarea>');
$(something).after(input);

But i also want to fill this textarea with content (when content exists of course), using php. sp now my code looks like this:

$var input = $('<textarea name="somename"><?=$variabel[0][something];?</textarea>');
$(something).after(input);

So the problem with this is that when i run this code the javascript automatically fills the content of the textarea in that input variable, and because there is more than one line it breaks so i get an error saying “Unexpected token ILLEGAL”

I hope i explained it well, so i need somehow the put the content of the textarea inside that generated textarea, but in a way in which my input doesn’t break.

Thans for any advice!

  • 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-05T18:35:57+00:00Added an answer on June 5, 2026 at 6:35 pm

    You can use the php function json_encode() to encode your PHP variable before it is output. It will convert newlines to \n, for example. More details about the function can be found here

    http://php.net/manual/en/function.json-encode.php

    In your case it would be something like this:

    var input = '<textarea name="somename"><?= json_encode($variabel[0][something]); ?></textarea>';
    

    Also refer to the following question: Pass a PHP string to a JavaScript variable (and escape newlines)

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

Sidebar

Related Questions

Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) So
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I'm
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I
Possible Duplicate: How to pass a variable / data from javascript to php and
Possible Duplicate: What's the best way to pass a PHP variable to Javascript? I
Possible Duplicate: Headers already sent by PHP My problem is that I have a
Possible Duplicate: How to pass a PHP variable to Javascript? I need to somehow
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: How to pass JS variable to php? pass a js variable to
Possible Duplicate: How to pass an array via $_GET in php? So I have

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.