Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have Javascript that I use to con 1

Status
Not open for further replies.

WildWest

Programmer
Apr 2, 2002
111
US
I have Javascript that I use to confirm the deletion of a file. Because it's interlaced with my ColdFusion app, I dynamically generate the onclick command that calls my script.

Here's my problem... When the onclick is dynamically generated from CF, It renders the HTML/onClick code as the following on some files with a "'" apostophy character in it. This is because my app happened to find a filename with a "'" in it. Since I can't control the filenames that the users upload, How can I get the following example to work without any nagging script debuggin errors???

Here's my javascript:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!--
function deleteFile(strName,strType){
if (confirm(&quot;Are you sure you want to delete this &quot; + unescape(strType) +&quot;?\n&quot; + unescape(strName))){
window.location=&quot;index.cfm?ACTION=DELETE&SUBDIR=&FILENAME=&quot; +escape(strName)+ &quot;&TYPE=&quot; +escape(strType);
}
}
//-->
</SCRIPT>

Here an example of it not working (because of the &quot;'&quot; in one of the filenames:

<A href=&quot;#&quot; onClick=&quot;deleteFile('Customer_Doc's','Dir')&quot;><img src=&quot;delete.jpg&quot; width=&quot;40&quot; height=&quot;15&quot; border=&quot;0&quot;></A>

THANKS IN ADVANCE FOR ANY HELP!!
 
The apostrophe between the c and the s in Doc's needs to be esacped otherwise Javascript interprets that as the end of the string and it messes up your code.

Code:
   onclick=&quot;deleteFile( 'Customer_Doc
Code:
\'
Code:
s', 'Dir' );&quot;>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top