Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  129] [ 1]  / answers: 1 / hits: 55546  / 15 Years ago, fri, december 4, 2009, 12:00:00

I have run into a problem where the user enters data and if there are single quotes at all, the script errors out.



What's the best way to handle single quotes that users enter so it doesn't interfere with the jquery/javascript?



UPDATE:



I'm sending it through ajax to a database. here is the data parameter for a json ajax call.

data: {str_ + sectionName + :' + UpdateText + ',EntityID: ' + EntityID + ' },

with update text being the string that can contain the quotes.


More From » jquery

 Answers
83

You could find one of the many String.replaceAll implementations or write your own, and just replace any single or double quotes with an escaped version like or '.


[#98151] Wednesday, December 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;