Naming a ColdFusion variable beginning with a number

The naming rules for creating ColdFusion variables are found here in the LiveDocs. The first bullet point is

  • A variable name must begin with a letter, underscore, or Unicode currency symbol.
However, I am doing some integration with SalesForce.com, and they have custom variables that are named like "00N30000000dqFd". Now, if I want to name a form variable with that name, and do some validation before posting the form, I was running into problems. Here is some sample code and comments that outline my struggles. If you comment out the 3 spots (lines 3, 8, and 13-15) that throw errors, the code will run and you will get the 3 cfdumps.

<cfset field = "00N30000000dqFd"> <!--- here is a variable that we assign a value starting with a number --->

<!--- <cfset 00N30000000dqFd = "test"> ---> <!--- variable starting with number throws error: "00N30000000dqFd," on line 3, column 8, is not a valid identifer name. --->
<cfparam name="form.#field#" default=""> <!--- paraming "00N30000000dqFd" in the form scope is ok --->
<cfdump var="#form#" label="after param">


<!--- <cfset "form.#field#" = "new value"> ---> <!--- doing this cfset method throws an error: The string "form.00N30000000dqFd" is not a valid ColdFusion variable name. --->
<cfset form["#field#"] = "1st value"> <!--- doing the structure method sets the variable ok --->
<cfdump var="#form#" label="after assigning">


<!--- <cfif IsDefined("form.#field#")> <!--- doing this IsDefined() method of checking if the variable exists in the Form scope throws an error: Parameter 1 of function IsDefined, which is now "form.00N30000000dqFd", must be a syntactically valid variable name.--->
   <cfset "form.#field#" = "2nd value">
</cfif>--->
<cfif StructKeyExists(form,field)> <!--- doing this structure key check method is ok --->
   <cfset form["#field#"] = "2nd value">
</cfif>
<cfdump var="#form#" label="end of demo">

Here is a demo of this in action.

Comments
Oyun's Gravatar super olmus thank you
http://www.aylak.com
# Posted by Oyun | 7/11/08 6:52 PM
Plastik's Gravatar Leah is definitely the one who should win. Science Fiction Conventions? What?! She deserves a win, indeed!
# Posted by Plastik | 11/14/08 6:49 AM
Estetik's Gravatar I'm guessing the only way to do this in Javascript would be to use the onresize event, and then using the resizeTo method to attempt to keep the window at the size you want?
# Posted by Estetik | 11/16/08 10:15 AM
Estetik's Gravatar I'm guessing the only way to do this in Javascript would be to use the onresize event, and then using the resizeTo method to attempt to keep the window at the size you want?
# Posted by Estetik | 11/16/08 10:18 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner