#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    13
    Rep Power
    0

    CF does not recognize function


    Hi:
    I have a portion of my CF app that invoke a javascript function 'MyFormatUPC' in the htm code.

    <html>
    <script language="javascript">
    function MyFormatUPC(UPCnumStr)
    {
    var loopnum;
    var tmpStr = "";
    var retStr = UPCnumStr;
    if (UPCnumStr.length < 12) {
    loopnum = (12 - UPCnumStr.length);
    for (i=1; i<=loopnum; i++) tmpStr = tmpStr.concat("0");
    retStr = tmpStr.concat(UPCnumStr);
    }
    return retStr;
    }
    </script>
    </head>

    <body>
    .....
    <tr>
    <cfset UPCPLU = MyFormatUPC(#upc_num#)>
    <cfset UPCPLU = #Insert("-", #upc_num#,2)#>
    <cfset UPCPLU = #Insert("-", UPCPLU,8)#>
    <td>#UPCPLU#</td>
    </tr>

    Here is the error I am encoutering from the browser:

    Variable MyFormatUPC is undefined.
    The error occurred on line 433.

    But 'MyFormatUPC' is defined inside the <head><head>. So why does it think 'MyFormatUP'C is undefined?

    Thanks
    Newbie
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,281
    Rep Power
    968
    JavaScript functions are defined in the user's browser. CFML runs on the server. You can't invoke a client JavaScript function from CFML (or any other server-side language).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by kiteless
    JavaScript functions are defined in the user's browser. CFML runs on the server. You can't invoke a client JavaScript function from CFML (or any other server-side language).
    The reason for invoking the function 'MyFormatUPC' is to 'left-pad' the upc number that is retrieved from the DB with leading zeroes before displaying on the screen. So if the upc number from the DB comes back as 1234, 'MyFormatUPC' will format it as 000000001234, then invoking the 'insert' function to insert '-' to make the number appears as 00-00000-01234 on the screen. If I cannpt invoke MyFormatUPC, can you tell me how I can left-pad the returned value from the DB?

    Thanks,
    newbie
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,281
    Rep Power
    968
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    13
    Rep Power
    0
    I found the NumberFormat function to do that.....it is working

IMN logo majestic logo threadwatch logo seochat tools logo