• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript error when calling a function

 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am list of filesnames coming from database. And i itreate over the list and display the file names. User has the option to click the file name to open the file. To open the file i call a javascript function and pass Filname and Username. My problem sometime file name are entered with singquotes. This breaks the javascript and i get an javascript error. To overcome this i wrote an java method to replace single quotes with \' and the build the javascript function. Still i get the javascript error
"Expected )".And i dont understand why it is coming.

This is the following piece of code,

<%

<td class='editable-section'>
<a
href="#"
onCliick="javascript:funOpenAttachment('<%= Util.escape(Content.getContentName()) %>',
'<%=strUsrNm%>');return false;">
<%=Content.getContentName()%>
</a>
</td>

In the Util.escape method i replace Single Quotes with \'. But i still get the javascript error.

Can anyone help me how to solve this. This would be of great help to me.Thanks in Advance.

Regards,
Arul
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add two slashes on your serverside code
\\'

Eric
 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Eric for a Quick Reply. I escaped ' with \\\\\'. And it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic