Updating textarea with Ajax: unterminated string literal

Posted Posted by Wes in Ajax, Ruby on Rails     Comments 1 comment
Mar
18

If you try to update a textarea with newlines in it via Ajax, you may get an “Unterminated string literal” error. The update coming back may look like this:

$('textarea_to_update').value='line one
line two
line three';

This will fail because the javascript will interpret the newline as the end of the command.

So, replace those newlines with the newline character and the textarea will get updated correctly:

textarea_value.gsub!(/\n/, '\n')

1 Comment to “Updating textarea with Ajax: unterminated string literal”

  • thanks, just what i was looking for!

Post comment

about databasically

We live and work in Kansas City, USA.

We're passionate about helping small businesses succeed and want to help you use technology to get more done.

From server, desktop, network management to programming custom web applications in Ruby on Rails, we're here to lend a hand.

Contact us if you have any questions!