aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Javascript error when calling a function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript error when calling a function" Watch "Javascript error when calling a function" New topic
Author

Javascript error when calling a function

Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Add two slashes on your serverside code
\\'

Eric
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
Thanks a lot Eric for a Quick Reply. I escaped ' with \\\\\'. And it worked.
 
 
subject: Javascript error when calling a function