Cfscript function vs cffunction

Just passing on something I ran across recently:  I have a page that has 2 nested CFLOOP's, and a UDF function call inside the inner loop.  The page was consistently taking about 75 seconds to run.  Just out of curiousity, I changed the UDF from a CFSCRIPT function to a CFFUNCTION, and the load time went from 75 seconds to less than 5.  At first I thought I broke it, and it was not really running, but it was I double-checked, and it was running properly and returning the same results.  Probably not significant if a function is called 1 or 2 times on a page, but if it's 100's or 1000's, it could be a big improvement.  This is CF8.

I was originally working on this a couple of months ago, but didn't have time to post this then due to a long vacation soon after that.  Since then the code has evolved, and I don't have an exact example to post.  But after thinking back, I believe the 2 nested CFLOOPs were actually inside a CFOUTPUT loop.  So with 3 nested loops, the function could have been executing 100,000 times (or more) on one page.  Even if just a fraction of a second improvement, this would be a major difference.  I'm guessing the CFFUNCTION somehow keeps itself instantiated memory, so that later calls are faster?
I have since done this translation to CFFUNCTION in other places with minor improvements, but these are being called many times fewer on a page.
Whenever comparing execution times, I do reload the original several times, and then reload the revised several times...  just to make sure the results are consistent and accurate.

Similar Messages

  • Help:Function call from CFScript

    I need to write a function call within
    <cfscript></cfscript> but not sure with the syntax. I
    got error message with the suntax I wrote (see below).
    All I need is for the function AddVal () to pass an Array
    within the existing loop.
    <CFSCRIPT>
    //Existing codes
    Function ExistingFunction(ParameterA) {
    //some codes here
    for ( i = 1; i LTE listLen( fileCon, crlf ); i = i + 1 ) {
    //some codes was written here to generate a 2 dimensional
    Array called: MyArray
    // I need to write my function here, so on every loop it
    will pass an array to be inserted to DB
    function AddVa(MyArray); >>>>> ??????????????
    <CFFUNCTION name="AddVal">
    <cfargument name="MyVal" type="Array" required="true">
    <cfquery name="MyQuery datasource="MyDatasource>
    // insert statement here
    </cfquery>
    </CFFUNCTION>
    </CFSCRIPT>

    pls try this.
    //syntax to call a function inside cfscript is given below.
    //variablename = functionname(pass ur argument);
    change ur code like this.
    <!--- First, clean up the CFSCRIPT block --->
    <CFSCRIPT>
    function ExistingFunction(ParameterA) {
    //some codes here
    for ( i = 1; i LTE listLen( fileCon, crlf ); i = i + 1 ) {
    //some codes was written here to generate a 2 dimensional
    Array called: MyArray
    getIP=AddVal(MyArray);//syntax to call a function inside
    cfscript.
    </CFSCRIPT>
    <!--- since you're doing a query move this function
    outside the CFSCRIPT block
    ...you can still call it from your CFSCRIPT block --->
    <CFFUNCTION name="AddVal">
    <cfargument name="MyVal" type="Array" required="true">
    <cfquery name="MyQuery datasource="MyDatasource>
    // insert statement here
    </cfquery>
    </CFFUNCTION>
    try this and inform.

  • Use or dont use cfscript by creation functions

    Hi
    The title is the question:
    What to use:
    [code]
    <cffunction name="WelcomeMsg" returntype="string">
    <cfargument name="name" type="string" required="yes">
    <cfreturn 'Hi '& name>
    </cffunction>
    [/code]
    Or
    [code]
    <cfscript>
    function WelcomeMsg(name){
    return 'Hi '& name;
    </cfscript>
    [/code]
    Are both of the function correct? Of am I not allowed to use
    the second function (may-b it is an old style and CF is trying to
    drop it or something, Does someone knows?)

    Both are correct and will work, but cffunction has some
    advantages. The biggest one is the cfargument tag which gives you
    more control over the datatypes coming in. You could code all those
    in cfscript, but it's now unnecessary.

  • The value returned from the load function is not of type numeric  errors after migration to Coldfusion 11

    I am currently testing our website with CF11. It is currently working with CF8 however after migrating it to a new server running CF11 I have encountered the following error.
    The value returned from the load function is not of type numeric.
    The error occurred in
    D:/Applications/CFusion/CustomTags/nec/com/objects/address.cfc: line 263
    Called from D:/Applications/CFusion/CustomTags/nec/com/objects/contact.cfc: line 331
    Called from D:/Applications/CFusion/CustomTags/nec/com/objects/user.cfc: line 510
    Called from D:/Applications/CFusion/CustomTags/nec/com/objects/user.cfc: line 1675
    Called from D:/website/NECPhase2/action.validate.cfm: line 54
    261 : <cfif isNumeric(get.idCountry)>
    262 : <cfset rc = this.objCountry.setID(get.idCountry)>
    263 : <cfset rc = this.objCountry.load()>
    264 : </cfif>
    265 : <cfset this.sPostcode = get.sPostcode>
    Have there been any changes between CF8 and CF11 that could  cause this error?
    Does anyone have ideas?

    This is the code in file object file country.cfc (nec.com.objects.country):
    <cfcomponent displayname="Country object" hint="This is a Country object, it allows you to access and set values in the Country.">
    <!---
    // Construct this object
    --->
    <cfset this.objFunctions = CreateObject( 'component', 'nec.com.system.functions' )>
    <cfscript>
      this.idCountryID = 0;
      this.sCountryName = "";
      this.sISOCode = "";
      this.sDHLCode = "";
      this.iErrorID = "";
    </cfscript>
    <!---
    // The following functions are the setters and getters. offering us a better way to get
    // at the contents of the object
    --->
    <!---
    // Getters
    --->
    <cffunction name="getID" displayname="Get ID" returntype="numeric" output="false" hint="This returns the ID of the current item.">
      <cfreturn this.idCountryID>
    </cffunction>
    <cffunction name="getsCountryName" displayname="Get sCountryName" returntype="string" output="false" hint="This gets the sCountryName value of this item.">
      <cfreturn this.sCountryName>
    </cffunction>
    <cffunction name="getsISOCode" displayname="Get sISOCode" returntype="string" output="false" hint="This gets the sISOCode value of this item.">
      <cfreturn this.sISOCode>
    </cffunction>
    <cffunction name="getsDHLCode" displayname="Get sDHLCode" returntype="string" output="false" hint="This gets the sDHLCode value of this item.">
      <cfreturn this.sDHLCode>
    </cffunction>
    <cffunction name="iError" displayname="Get iError" returntype="numeric" output="false" hint="This returns the iError of the current item.">
      <cfreturn this.iError>
    </cffunction>
    <!---
    // Setters
    --->
    <cffunction name="setID" displayname="Set ID" returntype="boolean" output="false" hint="This sets the ID value of this item.">
      <cfargument name="idCountryID" required="true" type="numeric" displayname="ID" hint="The ID to use.">
      <cfset this.idCountryID = arguments.idCountryID>
      <cfreturn true>
    </cffunction>
    <cffunction name="setsCountryName" displayname="Set sCountryName" returntype="boolean" output="false" hint="This sets the sCountryName value of this item.">
      <cfargument name="sCountryName" required="true" type="string" displayname="sCountryName" hint="The sCountryName to use.">
      <cfset this.sCountryName = arguments.sCountryName>
      <cfreturn true>
    </cffunction>
    <cffunction name="setsISOCode" displayname="Set sISOCode" returntype="boolean" output="false" hint="This sets the sISOCode value of this item.">
      <cfargument name="sISOCode" required="true" type="string" displayname="sISOCode" hint="The sISOCode to use.">
      <cfset this.sISOCode = arguments.sISOCode>
      <cfreturn true>
    </cffunction>
    <cffunction name="setsDHLCode" displayname="Set sDHLCode" returntype="boolean" output="false" hint="This sets the sDHLCode value of this item.">
      <cfargument name="sDHLCode" required="true" type="string" displayname="sDHLCode" hint="The sDHLCode to use.">
      <cfset this.sDHLCode = arguments.sDHLCode>
      <cfreturn true>
    </cffunction>
    <!---
    // Clear, to empty out the contents of this object
    --->
    <cffunction name="clear" displayname="Clear items Details" returntype="boolean" output="false" hint="Clears out all of the items details.">
      <cfscript>
       this.sCountryName = "";
       this.sISOCode = "";
       this.sDHLCode = "";
       this.iErrorID = "";
      </cfscript>
      <cfreturn true>
    </cffunction>
    <!---
    // The following functions deal with the load, save and deleting of objects
    --->
    <!---
    // Load
    --->
    <cffunction name="load" displayname="Load items details" returntype="numeric" output="false" hint="This loads in all the information about an item.">
      <cfset rc = this.clear()>
      <!---
      // First of all we need to get the name of the data source we are going to be using
      --->
      <cfscript>
      objDS = CreateObject("component","nec.com.system.settings");
      sDatasource = objDS.getDatasource();
    </cfscript>
      <!---
      // Check to see if it exists
      --->
      <cftry>
       <cfquery name="checkID" datasource="#sDatasource#">
        SELECT idCountryID
        FROM tblCountry
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("load: checkID: '#this.idCountryID#' #cfcatch.detail#");
        </cfscript>
        <cfset this.iErrorID = iErrorID>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfif not checkID.recordCount>
       <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         if(isDefined("session.afr")){
          whichOne = "#session.afr.getsAFRNumber()#";
         } else {
          whichOne = "";
         iErrorID = objError.addError("A Country with that id doesn't exists.[#this.idCountryID#][#whichOne#]");
        </cfscript>
       <cfset this.iErrorID = iErrorID>
       <cfreturn iErrorID>
      </cfif>
      <!---
      // If we got past all then then load in the details
      --->
      <cftry>
       <cfquery name="get" datasource="#sDatasource#">
        SELECT idCountryID, RTRIM(sCountryName) as sCountryName, RTRIM(sISOCode) as sISOCode, RTRIM(sDHLCode) as sDHLCode
        FROM tblCountry
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("load: get: #cfcatch.detail#");
        </cfscript>
        <cfset this.iErrorID = iErrorID>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfset this.idCountryID = get.idCountryID>
      <cfset this.sCountryName = get.sCountryName>
      <cfset this.sISOCode = get.sISOCode>
      <cfset this.sDHLCode = get.sDHLCode>
      <cfset this.iErrorID = "">
      <cfreturn true>
    </cffunction>
    <!---
    // Save
    --->
    <cffunction name="save" displayname="Save items Details" returntype="numeric" output="false" hint="Saves (to some source) the current details for the ID of the item.">
      <!---
      // First of all we need to get the name of the data source we are going to be using
      --->
      <cfscript>
      objDS = CreateObject("component","nec.com.system.settings");
      sDatasource = objDS.getDatasource();
    </cfscript>
      <!---
      // Now check to see if ithat ID exists
      --->
      <cftry>
       <cfquery name="checkID" datasource="#sDatasource#">
        SELECT idCountryID
        FROM tblCountry
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("save: checkID: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <!---
      // If it doesn't exist, then add the record, otherwise update the record
      --->
      <cfif not checkID.recordCount>
       <cfreturn this.add()>
      <cfelse>
       <cfreturn this.update()>
      </cfif>
    </cffunction>
    <!---
    // Add
    --->
    <cffunction name="add" displayname="Add Country" returntype="numeric" output="false" hint="This adds a Country.">
      <!---
      // Check to see if that a different item isn't already using the same unique details
      --->
      <cftry>
       <cfquery name="checkUnique" datasource="#sDatasource#">
        SELECT idCountryID
        FROM tblCountry
        WHERE sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#'
        OR sISOCOde = '#this.objFunctions.scrubText(this.sISOcode)#'
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("add: checkUnique: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfif checkUnique.recordCount>
       <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("A Country with that name or ISO code already exists. idCountryID=#checkUnique.idCountryID#");
        </cfscript>
       <cfreturn iErrorID>
      </cfif>
      <cftry>
       <cfquery name="add" datasource="#sDatasource#">
        SET nocount on
        INSERT INTO tblCountry(sCountryName, sISOCode, sDHLCode)
        VALUES('#this.objFunctions.scrubText(this.sCountryName)#','#this.objFunctions.scrubText(t his.sISOCode)#','#this.objFunctions.scrubText(this.sDHLCode)#')
        SELECT @@identity as autoID
        SET nocount off  
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("add: add: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfreturn add.autoID>
    </cffunction>
    <!---
    // Update
    --->
    <cffunction name="update" displayname="Update Country" returntype="numeric" output="false" hint="This updates a Country record.">
      <!---
      // Check to see if that a different item isn't already using the same unique details
      --->
      <cftry>
       <cfquery name="checkUnique" datasource="#sDatasource#">
        SELECT idCountryID
        FROM tblCountry
        WHERE (sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#'
        OR sISOCOde = '#this.objFunctions.scrubText(this.sISOcode)#')
        AND idCountryID <> #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("update: checkUnique: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfif checkUnique.recordCount>
       <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("Another Country with that name already exists. idCountryID=#checkUnique.idCountryID#");
        </cfscript>
       <cfreturn iErrorID>
      </cfif>
      <!---
      // Attempt to update the record to the datasource
      // if this fails for any reason then we submit an error message
      // to the error component and return the ID of the error
      --->
      <cftry>
       <cfquery name="update" datasource="#sDatasource#">
        UPDATE tblCountry
        SET sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#',
        sISOCode = '#this.objFunctions.scrubText(this.sISOCode)#',
        sDHLCode = '#this.objFunctions.scrubText(this.sDHLCode)#'
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("update: update: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfreturn this.idCountryID> 
    </cffunction>
    <!---
    // Delete
    --->
    <cffunction name="delete" displayname="Delete Country" returntype="numeric" output="false" hint="This deletes a Country record.">
      <!---
      // First of all we need to get the name of the data source we are going to be using
      --->
      <cfscript>
      objDS = CreateObject("component","nec.com.system.settings");
      sDatasource = objDS.getDatasource();
    </cfscript>
      <!---
      // Now check to see if ithat ID exists
      --->
      <cftry>
       <cfquery name="checkID" datasource="#sDatasource#">
        SELECT idCountryID
        FROM tblCountry
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("delete: checkID: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfif not checkID.recordCount>
       <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("A Country with that id doesn't exists, delete failed.");
        </cfscript>
       <cfreturn iErrorID>
      </cfif>
      <!---
      // Now check to see if there are any dependancies, if so we can't delete the item
      --->
      <cftry>
       <cfquery name="checkDependancies" datasource="#sDatasource#">
        SELECT idCountry
        FROM tblAddress
        WHERE idCountry = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("delete: checkDependancies: idCountry: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfif checkDependancies.recordCount>
       <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("That Country is being used by an address, delete failed.");
        </cfscript>
       <cfreturn iErrorID>
      </cfif>
      <!---
      // Now attempt to remove the record.
      // if this fails for any reason then we submit an error message
      // to the error component and return the ID of the error
      --->
      <cftry>
       <cfquery name="delete" datasource="#sDatasource#">
        DELETE FROM tblCountry
        WHERE idCountryID = #this.idCountryID#
       </cfquery>
       <cfcatch>
        <cfscript>
         objError = CreateObject("component","nec.com.system.errors");
         iErrorID = objError.addError("delete: delete: #cfcatch.detail#");
        </cfscript>
        <cfreturn iErrorID>
       </cfcatch>
      </cftry>
      <cfreturn this.idCountryID>
    </cffunction>
    </cfcomponent>

  • CFFUNCTION not working

    I am using CF5.0, but <CFFUNCTION> tag seems not
    working.
    Below is my codes,
    - Codes -
    <cffunction name="funcWelcomeMsg" returntype="string">
    <cfparam name="strUsername" type="string">
    <cfreturn strUrername>
    </cffunction>
    - Error -
    ColdFusion cannot determine how to process the tag
    <CFFUNCTION>. The tag name may be misspelled.
    If you are using tags whose names begin with CF but are not
    ColdFusion tags you should contact Allaire Support.

    Hi,
    Try doing it using <cfscript>
    <cfscript>
    function myFunction() {
    </cfscript>
    I do not think you can do it that way in CF 5. Is it possible
    for you to upgrade to at least ColdFusion MX? If so then your code
    would work I presume.
    -Westside

  • Please help with cfscript error!

    When I run my app, I got this error:
    sdfst_catcherror is recording this error: Context validation
    error for tag cfscript.; The start tag must have a matching end
    tag. An explicit end tag can be provided by adding
    </cfscript>. If the body of the tag is empty you can use the
    shortcut <cfscript .../>.
    The CFML compiler was processing:
    a cfscript tag beginning on line 45, column 4.
    a cfscript tag beginning on line 45, column 4.
    When I checked my codes, all the
    <cfscript></cfscript> have the pairs. There are only 2
    pairs of <cfscript</cfscript> in this template.
    See my code structure below:
    <!--- the first <cfscript pair> --->
    <cfscript>
    function getTRS(var5)
    some codes here...
    return TRS;
    </cfscript>
    <cffunction name="FrmTxt" returntype="Struct">
    <cfargument name="EmpCodes" required="true"
    type="array">
    <cfargument name="EmpID" required="true"
    type="numeric">
    <cfquery name="GetEmpInfo>
    Select * from......
    </cfquery>
    <cfset varFrms = GetEmpInfo.EmpCodes>
    <cfset A_Key = 1>
    <cfset structFrmTxt = StructNew()>
    <!--- The second pair --->
    <cfscript>
    Some codes here....
    Need to output #TRS# returned by getTRS(var5) set above
    </cfscript>
    <cfreturn structFrmTxt>
    </cffunction>
    From other CF forum I learned that I can't put getTRS(var5)
    within the second <cfscript></cfscript> within
    <CFFUNCTION> pair
    it says "You can't put UDF within UDF or method within
    method". When I did originally, I got this error:
    Unable to complete CFML to Java translation, Error
    information unsupported statement: class
    coldfusion.compiler.ASTfunctionDefinition
    I'm stuck and can't find any resources to solve this problem
    anymore, please help!....

    When I checked my codes, all the
    <cfscript></cfscript> have the pairs.
    This error can often mean that you did not properly end a
    previous code
    block or line. So the closing </cfscript> is being
    considered part of
    that unclosed code. For me, it is often a missing semi-colon
    [;] on the
    last line I wrote, missing a closing curly bracket [}] could
    do it as well.
    Check your code, this is seldom more then missing a bit of
    syntax.

  • Function references and stateful cfcs?

    Using 8.0.1
    ok, i have a happy component (example4.cfc):
    <cfcomponent output="false">
    <cfscript>
      variables.txt = "un-init";
    </cfscript>
    <cffunction name="Init" access="public" returntype="example4" output="false">
      <cfscript>
      variables.txt = "init";
      </cfscript>
      <cfreturn this />
    </cffunction>
    <cffunction name="remoteEcho" access="remote" returntype="string" ExtDirect="true" output="false">
      <cfargument name="str" type="string" required="true" />
      <cfreturn str &  "[" & variables.txt & "]"/>
    </cffunction>
    </cfcomponent>
    and I am trying to call a function reference like so:
    <cfscript>
    cfc = CreateObject('Component', 'Example4').Init();
    method = cfc['RemoteEcho']; //<- try to create function reference
    </cfscript>
    <cfdump var="#cfc#">
    <cfdump var="#method#">
    <cfdump var="#cfc.remoteEcho('bobo')#"><!--- this works, naturally --->
    <cfdump var="#method('bobo')#"><!--- failure here --->
    The problem that I am running into is that it cannot find the variables.txt private member.
    Element TXT is undefined in VARIABLES.
    The direct call works fine, however the reference acts as if it's, i don't know, a regular UDF outside of a cfc?
    Any help here, or will this just not work?
    -Jim

    As far as I know it will not work if you're accessing private
    variables because I seem to remember that the function reference is
    not tied to the cfc instance.
    Mack

  • Cfelseif with cfscript

    Hi all,
    I want to add to this code with an elseif
    Will it work to put in before the else in the udf.cfm code
    below the following? TIA:
    elseif (referer contains 'yahoo.com')
    StartPos=ReFindNoCase('q=.',referer);
    if (StartPos GT 0) {
    EndString=mid(referer,StartPos+2,Len(referer));
    Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
    Keywords=URLDecode(Keywords);
    return Keywords;
    udf.cfm
    <cfscript>function getGoogleKeywords(referer) {
    var Keywords='';
    var StartPos=0;
    var EndString='';
    if (referer contains 'google.com') {
    StartPos=ReFindNoCase('q=.',referer);
    if (StartPos GT 0) {
    EndString=mid(referer,StartPos+2,Len(referer));
    Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
    Keywords=URLDecode(Keywords);
    return Keywords;
    else {
    return '';
    }</cfscript>

    quote:
    Originally posted by:
    cf_dev2
    > Will it work to put in before the else
    Did you try it? An if / elseif / else works the same as a
    cfif/cfelseif/cfelse.
    Really?
    I always use two words, "else if"
    Guess there's always more than one way that works.

  • Javascript to cfscript

    Hello Gurus
    Wondering if this is possible?
    (CFMX 5)
    I have a cfscript function:
    <cfscript>
    function doSomething(thingToDo) {
    return URLEncodedFormat(Encrypt(thingToDo,myKey));
    </cfscript>
    takes 'thingTodo', encrypts it with private key and then
    makes friendly to use over URLs.
    Now I want to pass in a JS variable instead of a raw string,
    something like this:
    <cfoutput>
    <select name="selectObject"
    onchange="javascript:location.href='somepage.cfm?#doSomething(this.value)#'">
    <option value = "option1">Option 1
    <option value = "option2">Option 2
    </select>
    </cfoutput>
    so that thepage forwards to:
    somepage.cfm?with_encrypted_js_variable_here
    Is there a way to do this?
    I have no hair left, so any pointers in the right direction
    appreciated
    Jam

    Not sure if this is what your looking for but... how about
    this?
    Note: if you want to encrypt the values on the fly you'll
    need to encode ( or encrypt ) through javaScript. I beieve the cold
    fusion and javaScript are processed and run at different times.
    <cfscript>
    myKey = 'test';
    function doSomething(thingToDo) {
    return URLEncodedFormat(Encrypt(thingToDo,myKey));
    </cfscript>
    <script language="javascript">
    function loadURL(str) { self.location.href = 'somepage.cfm?'
    + str; }
    </script>
    <cfoutput>
    <select name="selectObject"
    onchange="loadURL(this.value)">
    <option value = "#doSomething('option1')#">Option 1
    </option>
    <option value = "#doSomething('option2')#">Option 2
    </option>
    </select>
    </cfoutput>

  • Cfscript

    I have a client side button that, when clicked, links to a
    server side page with delete queries. However, I must give the user
    a confirmation message making sure they really want to delete the
    current record. I am attempting to perform this via JavaScript
    within <cfscript> tags. However, I am having some troubles.
    Below is the code....the first part is in the <head> section
    (CR4203.cfm is the server side page with the deletion queries), and
    the button itself is in the <body>. Any ideas how to get this
    working, or a new approach I can take???
    <cfscript>
    function ConfirmDelete() {
    if (confirm("Click OK to Delete this CR.")) {
    window.location="CR4203.cfm";
    </cfscript>
    <cfscript>
    <input type="button" name="Delete" value="DELETE CR"
    onclick="ConfirmDelete()">
    </cfscript>

    This should do it
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN">
    <html>
    <head><title>delete test</title>
    <script type="text/javascript">
    function ConfirmDelete() {
    if (confirm("Click OK to Delete this CR.")) {
    window.location="CR4203.cfm";
    </script>
    </head>
    <body>
    <form>
    <input type="button" name="Delete" value="DELETE CR"
    onclick="ConfirmDelete()">
    </form>
    </body>
    </html>

  • cfscript error

    Have a page that works fine
    on the dev server, but crashes with the following error on the production server:
    Context validation error for tag cfscript.
    The start tag must have a matching end tag. An explicit end tag can be provided by adding </cfscript>. If the body of the tag is empty you can use the shortcut <cfscript .../>.The CFML compiler was processing:
    a cfscript tag beginning on line 10, column 10.
    a cfscript tag beginning on line 10, column 10.
    The error occurred in D:\inetpub\wwwroot\MercedCOMVIP\contact_form.cfm: line 10
    8 :   <cfset var char = "">
    9 :
    10 :      <cfscript>
    11 :       for(i=1; i <= length; i++) {
    12 :         char = mid(chars, randRange(1, len(chars)),1);
    Here's the code referenced in the error:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <cffunction name="makeRandomString" returnType="string" output="false">
      <cfset var chars = "123456789">
      <cfset var length = randRange(4,6)>
      <cfset var result = "">
      <cfset var i = "">
      <cfset var char = "">
    <cfscript>
      for(i=1; i <= length; i++) {
    char = mid(chars, randRange(1, len(chars)),1);
    result&=char;
    </cfscript>
      <cfreturn result>
    </cffunction>

    Well, I changed the result&=char; line to result = result & char; - worked in dev,
    crashed with the same error in prod.  Turns out prod is running CF MX7!  I'm adding a captcha to the page, so
    i've got to upgrade to version 8.  That must be what's causing the error.
    Thanks

  • Cffunction adn cffile upload

    Hello to everyone !
    I have a problem to upload a file with cffunction :
    i created a cfc with a function 'upload' :
    <cffunction name="upload" access="remote"
    returntype="void">
    <cfargument name="image_big" type="any" required="no">
    <cffile action="upload" fileField="#arguments.image_big#"
    destination = "mylocation" nameConflict="overwrite"
    accept="image/*">
    </cffunction>
    but it doesn’t work with out submitting the form ..
    pleas help ..
    thanks !

    I believe you need to have the file submitted via a form if
    you want to use the <cffile action="upload" fileField="">
    method of cffile. Otherwise, how will the server gain access to the
    file itself?

  • CF 8.0 cfscript variable

    Pls check if this is a bug cos it seemed like the cfscript and main cfoutput shared the same variable:
    Result : 5
    Expeced Result: 1
    <cfscript>
    function  
    valid4D(str){
    if (len(str) neq 4) 
    return false; 
    if (Ucase(str) eq "XXXX") 
    return false; 
    for(i = 1; i lte 4; i = i + 1){c =
    Mid(str, i, 1); 
    if (Not Find(c, "0123456789xX")) 
    return false;}
    return true;}
    </cfscript>
    <cfloop 
    from="1" to="1" index="i">
    <cfif not #valid4D("5555")#>
    <cfset err= 1>
    </cfif>
    <cfoutput>#i#</cfoutput></cfloop>

    it seemed like the cfscript
    and main cfoutput shared the same variable:
    That is entirely possible. It does not look like you are VAR scoping your function variables. So when you declare your variables inside the function they are placed in the shared "variables" scope. The "variables" scope is accessible to the whole page, including your "main cfoutput".
    You need to VAR scope all of your function local variables so they do not leak into the shared "variables" scope. 
    function valid4D(str){
       VAR i = "";
       VAR c = "";
       .... etc ....

  • CFScript Reference Manual

    Does anyone know an URL for a
    ColdFusion 9 CFScript Reference Manual?
    ColdFusion 9 CFML Reference only contains CFML, not CFScript.
    Developing ColdFusion 9 Applications is more of a User Guide,
    not a Reference.
    Thanks.
    myscreenname0345

    Thanks Gentlemen.
    I'm looking for things like:
       1. function args
           Ex: cfoutput attributes inlcude: group, groupCaseSensitive, maxRows, query, startRow
           Which (if any) does writeoutput() support?
           And what is the arg order?
       2. Exceptions
           What exception types are thrown by each CFScript function?
       3. Function modifiers
          Are the same ones supported as in Java (e.g. public, private, protected, static, etc.)?
          Do they work exactly the same as in Java?
    This must be described somewhere.
    Thanks.
    myscreenname0345

  • Cfc/function error?

    high, sorry, this is going to be a long code, this is a
    function in my db access component. the stored procedure is running
    fine, the e-mail sending are also running fine, but the function
    itself is not. Here is the error message
    The start tag must have a matching end tag. An explicit end
    tag can be provided by adding </cffunction>. If the body of
    the tag is empty you can use the shortcut <cffunction .../>.
    The error occurred in
    /Applications/CF/wwwroot/SabryCorp/in/07/CFC/toDb.cfc: line 796
    794 : </cffunction>
    795 : <!--- The new function to replace the add function
    --->
    796 : <cffunction name="todb" access="public">
    797 : <!--- the structure that holds the information
    --->
    798 : <cfargument name="fields" type="struct"
    required="yes">
    which should normally indicate that I have some sort of
    overlapping tags, i checked could not find any
    Any Ideas? or is this a bug in cfm?

    Yes, there are two functions above it, but both are running
    without any problems.
    I found a work around, as strange as it can be, but when i
    moved the last two arguments a couple of line earlier everything
    seems to work fine. I think there might be a bug of some sort, but
    I could not figure it out!
    thanks

Maybe you are looking for