# Update a form field with an action

Source: https://zotonic.com/cookbook/1584/update-a-form-field-with-an-action

URI: https://zotonic.com/id/1584

Language: en

Set a visible value without duplicate element IDs.

On a page with the standard Zotonic browser scripts:

```django
<label for="{{ #choice }}">{_ Chosen value _}</label>
<input id="{{ #choice }}" name="choice" value="">
{% button text="Choose garden" action={set_value target=#choice value="Garden"} %}
```

Click the button and expect “Garden” in the field. Generated `#` IDs keep separate instances of the template distinct. If the chooser is inside a dialog, pass the target ID into that dialog template and add `action={dialog_close}` after setting the value.

This changes browser state only. Validate the value again in the server-side form handler before saving. A visitor can change an input regardless of how the chooser populated it.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1584?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1584?language=en>)
