locked
How can I escape single quotes in javascript ? RRS feed

  • Question

  • User1253338400 posted

    Hi 

    I have the following:

    recd.selectQry = 'select Account.Id  from Account where Account.Id IN ('87654321')';

    How can i format this / escape the single quotes in javascript  before sending to the sql server ?

    thanks

    Thursday, August 15, 2019 5:35 AM

Answers

  • User-719153870 posted

    Hi robby32,

    In JS, we can use backslash (\)  as escape character. Please refer to: https://www.w3schools.com/js/js_strings.asp.

    In your case,

    <script>
    var selectQry = 'select Account.Id from Account where Account.Id IN (\'87654321\')';
    alert(selectQry);
    </script>

    The result:

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 15, 2019 6:33 AM

All replies

  • User-719153870 posted

    Hi robby32,

    In JS, we can use backslash (\)  as escape character. Please refer to: https://www.w3schools.com/js/js_strings.asp.

    In your case,

    <script>
    var selectQry = 'select Account.Id from Account where Account.Id IN (\'87654321\')';
    alert(selectQry);
    </script>

    The result:

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 15, 2019 6:33 AM
  • User-474980206 posted

    or the simple:

       recd.selectQry = "select Account.Id  from Account where Account.Id IN ('87654321')";

    Thursday, August 15, 2019 4:37 PM