Reputation: 606
I am having a problem with ckeditor data. I have some ckeditor html data saved in my data base as a description. So when i need to update that description i need to set the data from the database and show it in the textarea in order to show user what was it. I'm using laravel 5.3. In order to do this i have tried this
var old_description = '<?php echo $Product->description;?>';
$('#detail').val(old_description);
But this is giving the following error
What is the problem and what should i do?
Upvotes: 0
Views: 444
Reputation: 6650
You should just use json_encode() from http://www.php.net/manual/en/function.json-encode.php
var old_description = '<?php echo json_encode($Product->description); ?>';
It takes care of converting < / >, escaping any other special characters as necessary, preserve spaces, etc.
Upvotes: 1
Reputation: 38
The description you are passing contains multiple lines witch produces a javascript error. Try encoding the variable when echoing.
<?php echo json_encode($Product->description);?>
Upvotes: 1