String manipulation, textarea and json

#1

hi guys, especially those with regexp expertise, how do we handle special characters such as quotes, new line breaks from textarea data submission with back-end processing expecting json format?
thanks.

#2

You can escape() strings in JS before sending to the back end.

HTH

– Denny

#3

Are you saying doing something like escape(document.getElementById(‘textareaID’).value) onsubmit?
Thanks.

#4

If you’re not using a framework like jQuery, then yes… that looks about right. Give it a shot and see if it works for you. If not, there are likely to be dozens of examples of using escape() on the interwebs that might help you formulate a solution.

– Denny

#5

It works pretty well, thank you Denny.

1 Like
#6

Odd, onSubmit="escape(document.getElementById(‘textareaID1’).value); escape(document.getElementById(‘textareaID2’).value); escape(document.getElementById(‘textareaID3’).value)" no longer works. Tested against current version of Firefox on Windows 10.

any insight?
thanks.