# JavaScript inserts

## Handling dynamic content (JavaScript inserts)

The system allows dynamic content to be inserted using JavaScript inserts. They can be used in the following places:

* in components **Formatted content (TextContent)**,
* in components **Label**,
* in the property **Label** available in other components.

{% hint style="warning" %}
The functionality *does not include* the component **Formatted content (TextContent)** placed in the area **of the Footer**.
{% endhint %}

### JavaScript insert format

The inserts have the form:

```js
<?js: return "value"; /** example JS code returning a value */ ?>
```

The content of the insert must always return a value (e.g. a string).

***

### Usage examples

#### 1. Returning a value depending on a form field

The insert below will return the text *"m1. "* only if the field with the identifier `GesTextField1` has been filled in:

```js
<?js: return getValue("GesTextField1") ? "m1. " : ""; ?>
```

***

#### 2. Handling a default and custom value (session variables)

In the example below, if the variable `etykietaWlasna` is empty or has the value `null`, the value from `etykietaDomyslna`.\
Both values are available as session variables:

```js
<?js: return (getValue("etykietaWlasna") == "" || getValue("etykietaWlasna") == null)
    ? "${etykietaDomyslna}"
    : "${etykietaWlasna}"; ?>
```

***

#### 3. Insert with HTML formatting

Depending on the value of the field `channel` content containing HTML is returned dynamically:

```js
<?js:
  return getValue("channel") == "mobile"
    ? "<b>Consent to telephone contact for marketing purposes.</b> <span class='optional' style='color:#bec2c3;'>(optional)</span>"
    : "Consent to telephone contact for marketing purposes. <span class='optional' style='color:#bec2c3;'>(optional)</span>";
?>
```

***

### Available JavaScript methods

As part of the inserts, you can use the methods described in the section:

[**Conditional expression language**](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/jezyk-wyrazen-definiowania-warunkow-warunki-z-getvalue)

This allows, among other things, referring to field values, comparisons, checking for empty values, etc.

***

### Important note regarding identifiers

In the content of inserts **we do not prefix component identifiers or variable names with the symbol `@`**.\
Correct example:

```js
getValue("GesTextField1")
```

Incorrect example:

```js
getValue("@GesTextField1")
```
