# 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 properties **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 following form:

```js
<?js: return "value"; /** sample 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 `customLabel` is empty or has the value `null`, the value from `defaultLabel`will be used.\
Both values are available as session variables:

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

***

#### 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

Within inserts, you can use the methods described in the section:

[**Conditional definition expressions language**](/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/jezyk-wyrazen-definiowania-warunkow-warunki-z-getvalue.md)

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")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/formularze/dynamicznosc-formularza/wstawki-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
