Say I have:
<form method="get" action="something.php"> <input type="text" name="name" /> </form> <input type="submit" />
How do I go about submitting that form with that submit button outside of the form, I think in HTML5 theres an action attribute for the submit but I'm not sure if thats fully cross-browser and if it isn't is there anyway to do this?
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. With this setup, clicking the Submit button will cause the form to be submitted.
submit : The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form> , or if the attribute is an empty or invalid value. reset : The button resets all the controls to their initial values, like <input type="reset">.
It is actually possible to "submit" a "form" without form-tags. what you need is an ajax-function, e.g. with jquery, which will get the values by id. But there is no reason not to use a form tho. you should use form tag.
Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML.
In HTML5, there is the form attribute. Basically
<form id="myform" method="get" action="something.php"> <input type="text" name="name" /> </form> <input type="submit" form="myform" value="Update"/>
A solution that works great for me, is still missing here. It requires having a visually hidden <submit>
or <input type="submit">
element whithin the <form>
, and an associated <label>
element outside of it. It would look like this:
<form method="get" action="something.php"> <input type="text" name="name" /> <input type="submit" id="submit-form" class="hidden" /> </form> <label for="submit-form" tabindex="0">Submit</label>
Now this link enables you to 'click' the form <submit>
element by clicking the <label>
element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With