Copy link to clipboard
Copied
Hi,
I want to add a hyperlink in every company name that it will show its name in a pop-up dialog. Therefore, I try to do it as the following:
<a href="##" onclick="javascript:select('#replace(getList.company_name#')">#getList.company_name#</a>
However, since some company names have single quote " ' ", it encounters error when handling these company name. Therefore, I try to change the program as the following:
<a href="##" onclick="javascript:select('#replace(getList.company_name,''','\'','ALL')#')">#getList.company_name#</a>
But, it does not work and shows me error "The value ', cannot be converted to a number."
Can anyone help me to solve this problem?
Let me rephrase my answer since I realized that might not have made sense - there is a typo in your syntax in how you are trying to reference the apostrophes. When defining your replace statement if you use the same character as the text qualifier in the function (in this case an apostrophe), you need to escape the character you are searching for in CF. The text to replace cannot be three apostrophes:
'''
Your choices are using a different qualifier (quotation marks - will work fine here since t
...Copy link to clipboard
Copied
urlencodedformat
Copy link to clipboard
Copied
You can also escape quotation marks and apostrophes in JavaScript using the backslash: \'
Copy link to clipboard
Copied
Let me rephrase my answer since I realized that might not have made sense - there is a typo in your syntax in how you are trying to reference the apostrophes. When defining your replace statement if you use the same character as the text qualifier in the function (in this case an apostrophe), you need to escape the character you are searching for in CF. The text to replace cannot be three apostrophes:
'''
Your choices are using a different qualifier (quotation marks - will work fine here since there is no conflict between the server side code and client side code) or escaping the qualifier (apostrophe) in CF by doubling it.
Does this work:
<a href="##" onclick="javascript:select('#replace(getList.company_name,"'","\'","ALL")#')">#getList.company_name#</a>
Copy link to clipboard
Copied
<cfset CompName = "D'zousa and CO">
<cfoutput>
<input type="hidden" name="MyCompany" id="MyCompany" value="#CompName#">
<a href="##" onclick="javascript:mypopup()">#(CompName)#</a>
</cfoutput>
<script language="javascript">
function mypopup()
{
var comp = '';
comp = document.getElementById('MyCompany').value;
alert(comp);
}
</script>