I'm using codeigniter and the controller send a value to view (I want to show it in textarea).
the value contains breakline \n as the data was inputted with textarea tag.
and I'm using jquery to read its data. I don't read it on html section (which will work perfectly) because it's easy for me to recognize and maintain every function like delete section/element, or add section/element.
I've been looking for any similar problem, but none is working.
so here is my code:
<script>
function init()
{
var render = '<textarea required id="some_id"><?= $test ?></textarea>
$('#some_div').html(render);
}
</script>
so there's an error and the result looks like this on my console:
so there are breakline and I'm guessing the problem is with the breakline because when declare a string value, it needs '+ at the end of it.
so I try to add it and here is my code.
<script>
function init()
{
<?php
$text = $some_data_from_controller;
$breaks = array("\r\n");
$test = str_ireplace($breaks, "'+\n'", $text);
?>
var render = '<textarea required id="some_id"><?= $test ?></textarea>';
$('#some_div').html(render);
}
</script>
so there's no error appear. but the breakline doesn't work. Here's the result on my web: