Reed Armstrong
Reed Armstrong

Reputation: 65

Removing apostrophes from database values to be passed as function parameters

I'd like to remove apostrophes from strings when passing them as parameters to a function.

But, I need to escape them inside a function call (or before) since I do not know the values that will be passed (db variables I can't escape from the database).

onclick="editName(\''+JSON.stringify(service['name']).replace("'","")+'\',\''+id+'\');

This removes the apostrophe, but adds extra quotes and a space before the first parameter. It looks like this:

onclick="editName('" testers"','919');"=""></i>

The ideal output should look like:

onclick="editName('testers','919');"=""></i>

Any help would be much appreciated!

Upvotes: 0

Views: 58

Answers (1)

Reed Armstrong
Reed Armstrong

Reputation: 65

onclick="editName(\''+service['name'].toString().split("'").join('')+'\',\''+id+'\');

Upvotes: 1

Related Questions