Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ESCAPE "comma" in Javascript

EDIT1:

btnDelete.Attributes.Add("onclick", String.Format(@"return DeleteRow('{0}',{1},{2},{3});", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), "'" + DataBinder.Eval(e.Row.DataItem, "Name") + "'"));

edit:

i get this error:

Message: Unterminated string constant

i am passing the value from code behind and some of my text have somethinh lke this:

Foo3, In.c

   //javascript
    function DeleteRow(rowId, rowIdx, Id, Name) {         
        var textForMessage = "return confirm('Are you sure you want to delete this record with the name: \n{0} \n{1}');";
        //removed code...  
       return result;
    }
like image 630
Nick Kahn Avatar asked Mar 20 '26 04:03

Nick Kahn


2 Answers

Do nothing. A comma has no special meaning inside a JavaScript string.

like image 152
Quentin Avatar answered Mar 22 '26 16:03

Quentin


You don't need to escape the comma. You should surround the entire string with quotes:

'Foo3, In.c'

If this string is inside another string which is also single-quoted you may need to escape the quotes.

like image 30
Mark Byers Avatar answered Mar 22 '26 18:03

Mark Byers