Right now, I'm using a CMS that displays the content of a textarea in a "Settings" page, on another page, but the content is copied inside some jQuery code:
$('textarea#envoi_contrat_conf').val('<cms:pages masterpage="gabarits.php" page_name="envoi-contrat-conferencier"><cms:show gabarit_content/></cms:pages>');
The content between the <cms:pages></cms:pages>
tags is what is being saved in that textarea on the "Settings" page.
But right now, if I enter this in the textarea of the Settings page :
Hello
This is
A test
It will be displayed the same way, keeping the line breaks in the jQuery code. So it will break it. My code would look like this:
$('textarea#envoi_contrat_conf').val('Hello
This is
A test');
What I need, is to make sure everything that is going to be inserted in that "val" section, replaces line breaks with something that will still keep the line breaks once being copied in the textarea.
If something like this would work, I would be fine with is:
$('textarea#envoi_contrat_conf').val('Hello<br>This is<br>A test');
But <br>
doesn't work inside a textarea.
Any ideas? Thanks a lot!
Someone linked another topic that was not related to my question.
Another user pointed out that I was looking for "\n" instead of actual line breaks. Thanks for his help.
But now I need to know how to replace actual line breaks in the code by "\n" instead. Since it's CMS generated content, I cannot hardcode a sentence. So I need to make sure even if the user makes line breaks in the textarea content, that it will appear with "\n" in the jQuery code instead of real line breaks in the code.
I tried this:
$('textarea#envoi_contrat_conf').val().replace(/\r\n|\r|\n/g,'\n');
Which successfully allow me to replace line breaks with something else, but the \n to be printed as is, not rendered. Thanks
tag with space in javascript](https://stackoverflow.com/questions/37815103/replace-all-br-tag-with-space-in-javascript) – dippas Jun 04 '18 at 00:26