> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/tutorials/building-widgets/wemscript/8-types/9-text.md).

# 9. Text

A `text` type variable is used to represent and manipulate a sequence of characters.

```
<?
    var @t: text
    @t := "Hello"
    @t := @t + " there."
    @t := ToUpper(@t)
?>
```

#### Postback

Writing a widget that uses a `text` property is quite straightforward and is likely the easiest type to implement.

```html
<? register input @TextProperty ?>
<input type="text" name="<?attr OutputId(@TextProperty) ?>" value="<?attr @TextProperty ?>">
```

You don't need to do anything special when using the `text` type in JavaScript, as it is similar to the `String` type in JavaScript.

```html
<? register input @TextProperty ?>
<input type="hidden" id="<?attr OutputId(@TextProperty) ?>" name="<?attr OutputId(@TextProperty) ?>">
<? startupscript ?>

    // It is important to use 'js' encoding when outputting the property value in JavaScript blocks.
    let value = <?js @TextProperty ?>;
    value = value.toUpperCase();

    console.log("Result in uppercase:", value);

<? end ?>
<? submitscript ?>

    const el = document.getElementById(<?js OutputId(@TextProperty) ?>);
    
    // Performing a postback with the text property is straightforward.
    el.value = "Hi, can you post me back please? ♡";

<? end ?>
```

#### Print Output Overview

Depending on the encoding format, different outputs are generated. Let's assume a variable `var @s: text` holds the value `">>> Stan Laurel & Oliver Hardy <<<"`. The following outputs will be generated:

| Encoding       | Output                                                          |
| -------------- | --------------------------------------------------------------- |
| `<?= @s ?>`    | \&gt;\&gt;\&gt; Stan Laurel \&amp; Oliver Hardy \&lt;\&lt;\&lt; |
| `<?attr @s ?>` | >>> Stan Laurel \&amp; Oliver Hardy \&lt;\&lt;\&lt;             |
| `<?js @s ?>`   | ">>> Stan Laurel & Oliver Hardy <<<"                            |
| `<?raw @s ?>`  | >>> Stan Laurel & Oliver Hardy <<<                              |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.wem.io/platform/tutorials/building-widgets/wemscript/8-types/9-text.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.
