Advertisement

04.15.2008 at 08:28AM PDT, ID: 23324060
[x]
Attachment Details

Escape quotes

Asked by BobCSD in Programming for ASP.NET, JavaScript

I have a button in asp.net VB that uses an onmouseover to send a text string to a function...

onmouseover="CallFunction(<%# Eval("ProductID") %>,replaceQuotes('<%# Eval("ProductName") %>'),1);return false;"

Notice I am passing a text string from the table field as the second parameter in the CallFunction. However, if that text string happens to have an apostrophe/single quote or a double quote, I want to call the replaceQuotes function to escape the quotes.

My replaceQuotes function looks like this:

function replaceQuotes(stringPhrase)
{
<!--
stringPhrase.replace("\"","&quot;");
stringPhrase.replace("\'","\\\'");
return stringPhrase;
//-->
}

However, it still errors and does not seem to escape the apostrophe.

Here is the error:
missing ) after argument list
[Break on this error] CallFunction(4,replaceQuotes('Chef Anton's Cajun Seasoning'),1);return false;

What am I missing?

thanks.



Start Free Trial
[+][-]04.15.2008 at 08:36AM PDT, ID: 21359631

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 08:43AM PDT, ID: 21359700

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 08:46AM PDT, ID: 21359735

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, JavaScript
Sign Up Now!
Solution Provided By: jrram
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.15.2008 at 09:03AM PDT, ID: 21359902

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 09:03AM PDT, ID: 21359903

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906