String manipulation, textarea and json

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?

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


– Denny

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

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

It works pretty well, thank you Denny.

1 Like

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?