0

I have a utf8 text that I'm trying to insert into a textarea. The code is pretty simple:

let initial_description = "{{ initial_decription }}";
$("#descripcion").html(initial_description);

But I get this error:

SyntaxError: unterminated string literal

Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180
  • Presumably the content of `initial_decription` contains double quotes, which then breaks your Javascript... – solarissmoke May 05 '18 at 14:21
  • See also https://stackoverflow.com/questions/298772/django-template-variables-and-javascript which highlights the dangers of this approach and offers some alternatives. – solarissmoke May 05 '18 at 14:27

1 Answers1

1

most likely in your {{ initial_decription }} exist quotes.

You can bypass the error by preloading data in hidden field.

Like This:

let initial_description = $("#initial_description").val();
$("#descripcion").html(initial_description);
<input type="hidden" id="initial_description" value="{{ initial_decription }}">
mscdeveloper
  • 2,749
  • 1
  • 10
  • 17