The rewritten title is: Use buttons outside the <form> tag to submit the form
P粉141911244
2023-08-21 16:26:37
<p>Translation result:</p>
<pre class="brush:php;toolbar:false;"><p>Suppose I have the following: <code><form method="get" action="something.php">
<input type="text" name="name" />
</form>
<input type="submit" /></code></pre>
<code>
<p>How do I submit this form using a submit button located outside the form? I know there is a submit action attribute in HTML5, but I'm not sure if it's fully cross-browser compatible. If not, is there any other way to achieve this functionality? </p></code>
In HTML5, there is form attribute. basically
<form id="myform" method="get" action="something.php"> <input type="text" name="name" /> </form> <input type="submit" form="myform" value="Update"/>Update: In modern browsers, you can use the
formattribute to achieve this .As far as I know, you can't achieve this functionality without using JavaScript.
This is the description in the specification
This is the part I bolded
submitButtons are considered controls.http://www.w3.org/TR/html4/interact/forms.html#h-17.2.1
Based on comments
Why not put the
inputinside the form, but use CSS to place it elsewhere on the page?