@If (JavaScript)

Executes a statement based on a conditional test.

Defined in

@Functions (JavaScript)

Syntax

@If(condition, statement, ..., ..., else) : any
Return value Description
condition A logical value, for example, n > 0.
statement A valid @function statement to be executed if the preceding condition is true. Use @Do to execute multiple statements.
else A valid @function statement to be executed if no condition is true. Use @Do to execute multiple statements.
any The result of the statement that is executed.

Usage

The condition and statement parameters must be in pairs. There can be any number of pairs.

The first true condition initiates execution of the paired statement and no further testing occurs. If no condition is true, the else statement executes.

Examples

This example is the onBlur event for the edit box binding field1. It converts the Celsius value in field1 to a Fahrenheit value for field2.
var n = @GetNumberField("//field1");
// condition
@If(n != "",
	@Do(
		n = 9 / 5 * n,
		@SetNumberField("//field2", n + 32)),
	// else
	@Do(
		@SetNumberField("//field1", 0),
		@SetNumberField("//field2", 32)));

This example returns the string Positive number, Negative number, or Zerodepending on the value of a number.

var n = @GetNumberField("//field3");
@Return(
	@If(
		n > 0, "Positive number",
		// else if
		n < 0, "Negative number",
		// else
		"Zero"
	)
);