Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an html button that passes a parameter?

I want a html button with parameter functionality.

new/?sorting=desc is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.

<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>

I want buttons that behave like these links:

<a href="./?sorting=desc">Äldst först</a> <a href="./?sorting=asc">Nyast först</a>

like image 717
Montao Avatar asked Nov 27 '22 06:11

Montao


1 Answers

If you want something to act as a link, then you should use a link.

That said:

When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.

You need to store the data in hidden inputs.

<form action="/social/tracking/new/">
     <input type="hidden"
            name="sorting"
            value="desc">
     <input type="submit" 
            value="Nyast först">
</form>
<form action="/social/tracking/new/">
     <input type="hidden"
            name="sorting"
            value="asc">
     <input type="submit" 
            value="Sort the other way">
</form>
like image 120
Quentin Avatar answered Dec 17 '22 18:12

Quentin