search

Home  >  Q&A  >  body text

The rewritten title is: Use buttons outside the <form> tag to submit the form

<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>
P粉141911244P粉141911244465 days ago408

reply all(2)I'll reply

  • P粉432906880

    P粉4329068802023-08-22 15:04:37

    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"/>

    reply
    0
  • P粉018548441

    P粉0185484412023-08-22 11:58:02

    Update: In modern browsers, you can use the form attribute 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 input inside the form, but use CSS to place it elsewhere on the page?

    reply
    0
  • Cancelreply