The ** autocalc** tag and script is used to update a text field dynamically based on a mathematical expression. The mathematical expression can include basic operations such as addition, subtraction, multiplication, and division, or nearly any expression using Javascript mathematical operations. In the mathematical expression, you reference individual variables.

**Note:** The `autocalc`

tag and script do not allow references to variables on pages other than the page where the tag and script are defined. If needed, it is instead recommended to use `dynamic value`

, which allows for such references and features other enhancements.

## Syntax

### Basic

Specify the mathematical statement as the input to the tag. Variable references can be used.

autocalc: Mathematical Statement

### Tables: row and column notation

If used in a table, it is possible to reference individual rows or columns using the built-in reference notation. The notation is useful when defining the mathematical expressions in a table where it's not practical to specify the specific variables. Instead, the notation is a shorthand that tells the system to automatically apply the expression across the entire table, either rows or columns or both.

Columns are lettered in sequence from A to Z and correspond to only the columns with inputs in them, excluding the left column that contains the question text. Rows are numbered in sequence from 1 to N, where N is the total number of rows available in the table. To reference a table column, use 'COL' + `colid`

(defaults to 1...N but can be set as A to Z if specified in the table syntax) and surrounded by double underscores (e.g., '__COLA__' for column A). To reference a table row, use 'ROW' + row number and surrounded by double underscores (e.g., '__ROW1__' for row 1). The example above used the variables corresponding to each row in the table. The below illustrates how to revise QAVG using the row reference notation.

autocalc: (__ROW1__ + __ROW2__ + __ROW3__) autocalc: (__COLA__ + __COLB__ + __COLC__)

There is also shortened notation to reference *all* columns or *all* rows in a table.

autocalc: add(__ALLCOLS__) autocalc: add(__ALLROWS__)

`add(__ALLCOLS__)`

automatically sums all of the columns, whereas `add(__ALLROWS__)`

automatically sums all of the rows.

## Examples

### Average row

Row variable AVG calculates the average of table inputs. A second `datatype`

tag (`datatype: number`

) is added directly to the AVG variable to allow for a possible non-integer average to be submittable.

### Total column

In the example below, the last column adds together all of the values at each of the columns automatically via `add(__ALLCOLS__)`

without needing to specify each individual column.

### Total row

In the example below, the TOT row adds together all of the values at each of the rows automatically via `add(__ALLROWS__)`

without needing to specify each individual row.

## Comments

0 comments

Please sign in to leave a comment.