0

I have this function that I use as a Custom Formatter in a JqGrid for ASP.NET WebForm

function formatLink(cellValue, options, rowObject) {
    var res = cellValue.split(" - ");
    var newLink = "";
    var value = rowObject['Filter'];
    var link = '<a class=\"clickCell\" href=\"#\" OnClick=\"CellClicked(\'value\')\">' + res[0] + '</a> - ' + res[1];
    newLink = link.replace("value", value).replace("'", "\'");
    return newLink;
}

the returned link does not work.

Here is an example:

<a onclick="CellClicked('vpd.esercizio = '2011-2012'')" href="#" class="clickCell">3</a>

As you can see, the var value contains string with quote. I will use its content to compose sql where condition.

Can you help me get things work?

1 Answer 1

0

Why don't you simply do

value.replace("'","\\'")
var link = '<a class="clickCell" href="#" OnClick="CellClicked('+value+')">' + res[0] + '</a> - ' + res[1];

?

With that replace you should be fine. I also removed some unnecesary back slashes because you can use double quotes inside simple quotes.

document.write(' "" '); returns ""

4
  • cause value usually containn somethig like vpd.esercizio = '2011-2012' Commented Feb 20, 2013 at 21:23
  • what's inside value and what it should be displayed? I think I misunderstood the question
    – martriay
    Commented Feb 20, 2013 at 21:25
  • As I wrote, value contains string with single quotes Commented Feb 20, 2013 at 21:29
  • can you manually write the string you want instead? you want to remove the single quotes or do you want to print them with a backslash?
    – martriay
    Commented Feb 20, 2013 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.