1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-06 16:48:01 +00:00

Add Submit A Form With A Button Outside The Form as an html til

This commit is contained in:
jbranchaud
2019-01-17 16:41:01 -06:00
parent 07a29d80cf
commit 7126a70e81
2 changed files with 31 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
# Submit A Form With A Button Outside The Form
You can tie a submit button to a form that the button doesn't live inside
of. The trick is to give the form an `id` and then reference that `id` with
the button's `form` property.
```html
<div>
<form id="my-form">
<label for="name">Name:</label>
<input type="text" name="name"></input>
</form>
<!-- ... -->
<button type="submit" form="my-form">Submit</button>
</div>
```
With this setup, clicking the _Submit_ button will cause the form to be
submitted.
See the [MDN Button
docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) for
more details.