View Full Version : Passing Javascript Replace function as an argument of user defined function

07-12-2011, 10:18 AM

I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it?

intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\'

I am posting my javascript function here:

<a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a>

function OpenDocPreview(url, docname) {
alert('message from search base : ' + url + ' ' + docname);

thank you,

07-12-2011, 10:29 AM
You need to look at attaching event handlers (http://www.quirksmode.org/js/events_advanced.html) rather than relying on "onclick".

07-12-2011, 10:36 AM
thank you for your suggestion, but i am getting a syntax error. i think the argument i am passing have some error.

07-12-2011, 10:46 AM
I meant you have to use those to solve this problem. replace(/\\/g,"\\\\") isn't going to do anything. The first parameter expects a string or regex pattern as a variable. You've given it /\\/g, which is, as far as the function is concerned, gibberish.

Edit, also, it probably needs to look more like /\\\\/g anyway. I'm not sure, I hate regular expressions, but your backslashes probably need to be escaped.

07-12-2011, 11:10 AM
yes i got your point. Can you provide some sample code to solve this issue by using event handler, as you mentioned.

thank you,