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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I set the cold fusion value in javascript?

Status
Not open for further replies.

anitalulu

Programmer
Nov 19, 2002
23
HK
I want to use a javascript's comfirm function to ask the user whether to overwrite the file during upload.

The code as follow
----------------------
<script language= &quot;JavaScript&quot;>
if (confirm(&quot;The file already exists. Are you sure you want to overwrite it?&quot;)) {
<cfscript>
session.overwrite = true;
</cfscript>
}
</script>

<cfif isdefined(&quot;session.overwrite&quot;) and session.overwrite eq true>
<cffile action=&quot;Upload&quot; filefield=&quot;form.#fieldname#&quot; destination=&quot;#GV_photo_path##StructFind(session.strFileDownload, InfoTypeID)#&quot; nameconflict=&quot;OVERWRITE&quot;>
<cfset session.strFilename[&quot;#id#&quot;][&quot;Filename&quot;] = &quot;#File.ServerFile#&quot;>
<cfset StructDelete(session, &quot;overwrite&quot;)>
</cfif>

However, no mather the user click &quot;OK&quot; or &quot;Cancel&quot;, the session.overwrite is true.

How can I avoid this problem?
 
<cfscript>
session.overwrite = true;
</cfscript>

That part will run on the server no matter what the java script around it is doing. Conditional client side script cannot effect something that the server has already done. to get a java variable back into coldfusion, you need to put it somewhere where they can both reach it, in a URL or FORM variable. I say both can reach it, but obviously not at the same time. Cold fusion can output a variable into the javascript to be ran in the client, javascript can put a variable through a URL or FORM.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top