r1 - 19 Sep 2005 - 11:39:11 - JonPriddeyYou are here: TWiki >  Main Web  >  ElixirReport > ElixirReportCookbook > JavaScriptSubstitution > JavaScript > VariablesWithSpaces

Variables with Spaces

When working with data records, Elixir tools make the fields of the current record available to scripts. For example, if a record has fields named DailyRate and DaysWorked you can reference these directly:

var amount = DailyRate * DaysWorked;
However, if the fields contain spaces, for example Daily Rate and Days Worked, you cannot access them directly because the names do not conform to JavaScript syntax. The same is true for fields like 2005 - it isn't a valid JavaScript name.

In order to access these fields, you can use the JavaScript indexing ability - by using square brackets you can access any variables, regardless of their name. For example:

var amount = this["Daily Rate"] * this["Days Worked"];

-- JonPriddey - 19 Sep 2005

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback