Skip to content

htmx, include hidden input fields outside of a form

New Course Coming Soon:

Get Really Good at Git

Using htmx I had a list of items, think a list of tasks, with task text and more details, and inside this list a “delete button”.

I had the need of sending some information that you’d usually use a hidden input element for.

Something invisible to the user but essential for my app needs.

But I couldn’t use a form for this, I just used a button element, because we can’t nest forms.

Turns our we can use the hx-vals attribute and pass a list of key-value pairs that are going to be added to the request just like a hidden input field would:

<button hx-delete="/item/..." hx-vals='{"key": "value"}' hx-target="#response">
  Delete
</button>
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Read my HTMX Tutorial on The Valley of Code
→ Read my Alpine.js Tutorial on The Valley of Code

Here is how can I help you: