How can 2 action be done in the form



  • <form action="myurl">
      <button name="test1">test1</button>
      <button name="test2">test2</button>
    </form>
    

    I'll get urles on the buttons:

    myurl?test1
    

    myurl?test2

    How do you get urles like this without js

    myurl/test1
    myurl/test2



  • Based on @Geslot, you can also use the attribute. https://webref.ru/html/button/formaction :

    <form>
    
    &lt;button formaction="myurl/test1"&gt;test1&lt;/button&gt;
    
    &lt;button formaction="myurl/test2"&gt;test2&lt;/button&gt;
    

    </form>


    Example with field:

    <form target="_blank">

    &lt;input type="text" name="q" value="Hello, World!"&gt;
    
    &lt;button formaction="//bing.com/search"&gt;Bing Search&lt;/button&gt;
    
    &lt;button formaction="//google.com/search"&gt;Google Search&lt;/button&gt;
    

    </form>

    https://jsfiddle.net/f5po9zck/


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2