Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the url sent to an html form?

Tags:

html

forms

Suppose we have:

 <form action="xxx">
     <input type="checkbox" id = "checkbox" name="checked" value="1">
     <input type="submit">Submit</input>
 </form>"

When click the submit button, the url should be something like "xxx?checked=1". In this case, I want to append another parameter to the url. I know using hidden value is an option, but do we have a more direct way? Please suggest. Thanks

like image 727
Edmond Avatar asked Oct 21 '22 08:10

Edmond


1 Answers

The fact is the url depends on the method you are using to send the form. This is set on the method attribute on the <form> tag.

The URL of the action can be any valid URL so to add extra attributes like something=1 and other=2 you could set the following:

<form action="xxx?something=1&other=2">
    <input type="checkbox" id="checkbox" name="checked" value="1">
    <input type="submit">Submit</input>
</form>

submitting the form will now send the GET request xxx?something=1&other=2&checked=1

like image 127
laconbass Avatar answered Nov 01 '22 08:11

laconbass