Scripting with FormCalc and JavaScript

Although FormCalc and JavaScript are intended for two different types of users, there is some overlap between the types of built-in functions they offer. The following table lists all available FormCalc functions and whether a comparable function exists within JavaScript.

For more information about FormCalc functions and their parameters, see Built-in function syntax.

FormCalc function

Description

JavaScript method equivalent

Abs(n1)

Returns the absolute value of a numeric value or expression.

Math.abs(n1)

Apr(n1, n2, n3)

Returns the annual percentage rate for a loan.

None

At(s1, s2)

Locates the starting character position of a string within another string.

String.search(s1)

Avg(n1 [, n2... ] )

Evaluates a set of number values and/or expressions and returns the average of the non-null elements contained within that set.

None

Ceil(n1)

Returns the whole number greater than or equal to a given number.

Math.ceil(n1)

Choose(n1, s1 [, s2... ] )

Selects a value from a given set of parameters.

None

Concat(s1 [, s2... ] )

Returns the concatenation of two or more strings.

String.concat(s1, s2 [, s3 ... ])

Count(n1 [, n2...])

Evaluates a set of values and/or expressions and returns the number of non-null elements contained within the set.

None

CTerm(n1, n2, n3)

Returns the number of periods needed for an investment earning a fixed, but compounded, interest rate to grow to a future value.

None

Date()

Returns the current system date as the number of days since the epoch.

Date.getDate()

The JavaScript Date object does not use the epoch as a reference point.

Date2Num(d1 [, f1 [, k1 ] ] )

Returns the number of days since the epoch, given a date string.

The JavaScript Date object does not use the epoch as a reference point.

DateFmt([ n1 [, k1 ] ] )

Returns a date format string, given a date format style.

None

Decode(s1 [, s2 ] )

Returns the decoded version of a given string.

Partial support

JavaScript only supports URL encoded values that contain no escape characters.

Encode(s1 [, s2 ] )

Returns the encoded version of a given string.

Partial support

JavaScript only supports URL encoded values that contain no escape characters.

Eval()

Returns the value of a given form calculation.

eval(s1)

Exists(v1)

Determines whether the given parameter is a valid reference syntax to an existing object.

None

Floor(n1)

Returns the largest whole number that is less than or equal to the given value.

Math.floor(n1)

Format(s1, s2)

Formats the given data according to the specified picture format string.

None

FV(n1, n2, n3)

Returns the future value of consistent payment amounts made at regular intervals at a constant interest rate.

None

Get(s1)

Downloads the contents of the given URL.

None

HasValue(v1)

Determines whether the given parameter is a valid reference syntax with a non-null, non-empty, or non-blank value.

None

IPmt(n1, n2, n3, n4, n5)

Returns the amount of interest paid on a loan over a set time.

None

IsoDate2Num(d1)

Returns the number of days since the epoch, given a valid date string.

None

IsoTime2Num(d1)

Returns the number of milliseconds since the epoch, given a valid time string.

None

Left(s1, n1)

Extracts a specified number of characters from a string, starting with the first character on the left.

String.substring(n1, n2)

Len(s1)

Returns the number of characters in a given string.

String.length

LocalDateFmt( [ n1 [, k1 ] ] )

Returns a localized date format string, given a date format style.

None

LocalTimeFmt( [ n1 [, k1 ] ] )

Returns a localized time format string, given a time format style.

None

Lower(s1 [, k1 ] )

Converts all uppercase characters within a specified string to lowercase characters.

String.toLowerCase(s1)

Ltrim(s1)

Returns a string with all leading white space characters removed.

None

You can use JavaScript regular expressions to perform this operation.

Max(n1 [, n2... ] )

Returns the maximum value of the non-null elements in the given set of numbers.

Math.max(n1, n2)

Min(n1 [, n2... ] )

Returns the minimum value of the non-null elements of the given set of numbers.

Math.min(n1, n2)

Mod(n1, n2)

Returns the modulus of one number divided by another.

Use the modulo (%) operator.

NPV(n1, n2 [, ... ] )

Returns the net present value of an investment based on a discount rate and a series of periodic future cash flows.

None

Num2Date(n1[, f1 [, k1 ] ] )

Returns a date string given a number of days since the epoch.

None

Num2GMTime(n1 [,f1 [, k1 ] ] )

Returns a GMT time string given a number of milliseconds from the epoch.

None

Num2Time(n1 [,f1 [, k1 ] ] )

Returns a time string given a number of milliseconds from the epoch.

None

Oneof(s1, s2 [, s3... ] )

Returns true (1) if a value is in a given set and false (0) if it is not.

None

This function is similar to the String.search(s1) method and String.match(expression) method.

Parse(s1, s2)

Analyzes the given data according to the given picture format.

None

Pmt(n1, n2, n3)

Returns the payment for a loan based on constant payments and a constant interest rate.

None

Post(s1, s2 [, s3 [, s4 [, s5 ] ] ] )

Posts the given data to the specified URL.

None

PPmt(n1, n2, n3, n4, n5)

Returns the amount of principal paid on a loan over a period of time.

None

Put(s1, s2 [, s3 ] )

Uploads the given data to the specified URL.

None

PV(n1, n2, n3)

Returns the present value of an investment of periodic constant payments at a constant interest rate.

None

Rate(n1, n2, n3)

Returns the compound interest rate per period required for an investment to grow from present to future value in a given period.

None

Ref()

Returns a reference to an existing object.

None

Replace(s1, s2 [, s3 ] )

Replaces all occurrences of one string with another within a specified string.

String.replace(s1, s2)

Right(s1, n1)

Extracts several characters from a given string, beginning with the last character on the right.

String.substring(n1, n2)

Round(n1 [, n2 ] )

Evaluates a given numeric value or expression and returns a number rounded to the given number of decimal places.

Math.round(n1)

Rtrim(s1)

Returns a string with all trailing white space characters removed.

None

You can use JavaScript regular expressions to perform this operation.

Space(n1)

Returns a string consisting of a given number of blank spaces.

None

Str(n1 [, n2 [, n3 ] ] )

Converts a number to a character string. FormCalc formats the result to the specified width and rounds to the specified number of decimal places.

String(n1)

or

Number.toString(radix)

Stuff(s1, n1, n2 [, s2 ] )

Inserts a string into another string.

None

Substr(s1, n1, n2)

Extracts a portion of a given string.

String.substring(n1, n2)

Sum(n1 [, n2... ] )

Returns the sum of the non-null elements of a given set of numbers.

None

Term(n1, n2, n3)

Returns the number of periods required to reach a given future value from periodic constant payments into an interest-bearing account.

None

Time()

Returns the current system time as the number of milliseconds since the epoch.

Date.getTime()

The JavaScript Date object does not use the epoch as a reference point.

Time2Num(d1 [, f1 [, k1 ] ] )

Returns the number of milliseconds since the epoch, given a time string.

None

TimeFmt([n1 [, k1 ] ] )

Returns a time format, given a time format style.

None

UnitType(s1)

Returns the units of a unitspan. A unitspan is a string consisting of a number followed by a unit name.

None

UnitValue(s1 [, s2 ] )

Returns the numeric value of a measurement with its associated unitspan after an optional unit conversion.

None

Upper(s1 [, k1 ] )

Converts all lowercase characters within a string to uppercase.

String.toUpperCase()

Uuid(n1)

Returns a Universally Unique Identifier (UUID) string to use as an identification method.

None

Within(s1, s2, s3)

Returns true (1) if the test value is within a given range, and false (0) if it is not.

String.search(s1)

WordNum(n1 [, n2 [, k1 ] ] )

Returns the English text equivalent of a given number.

None

// Ethnio survey code removed