| CARVIEW |
Select Language
HTTP/2 301
cache-status: "Netlify Edge"; fwd=miss
content-type: text/html
date: Fri, 26 Dec 2025 19:44:56 GMT
location: /examples/reset-user-input/
server: Netlify
strict-transport-security: max-age=31536000
x-nf-request-id: 01KDE32NZTDZCEEMWY8BX51V65
content-length: 98
HTTP/2 200
accept-ranges: bytes
age: 0
cache-control: public,max-age=0,must-revalidate
cache-status: "Netlify Edge"; fwd=miss
content-encoding: gzip
content-type: text/html; charset=UTF-8
date: Fri, 26 Dec 2025 19:44:56 GMT
etag: "c14da2378c3be00e07eb590116f1d31d-ssl-df"
server: Netlify
strict-transport-security: max-age=31536000
vary: Accept-Encoding
x-nf-request-id: 01KDE32P8G49572ECC6RXT7EJ8
</> htmx ~ Examples ~ Reset user input
Reset user input
This example shows how to easily reset user inputs using hx-on,
allowing users to make multiple requests without having to manually delete their previous inputs.
The inline script will run on the afterRequest event and ensures
that the form will reset to its initial state as long as the response has a 20x status code:
<form hx-post="/note"
hx-target="#notes"
hx-swap="afterbegin"
hx-on::after-request="if(event.detail.successful) this.reset()">
<div class="form-group">
<label>Add a note</label>
<input type="text" name="note-text" placeholder="blank canvas">
</div>
<button class="btn">Add</button>
</form>
<ul id="notes"><!-- Response will go here --></ul>
The reset() method is only available on form elements.
For other elements, the input value can explicitly selected and reset to a default to achieve the same result.
The following code is functionally equivalent:
<div>
<label>Add a note</label>
<input id="note-input" type="text" name="note-text" placeholder="blank canvas">
</div>
<button class="btn primary"
hx-post="/note"
hx-target="#note"
hx-swap="afterbegin"
hx-include="#note-input"
hx-on::after-request="if(event.detail.successful)
document.getElementById('note-input').value = ''">
Add
</button>
<ul id="notes"><!-- Response will go here --></ul>
Server Requests ↑ Show