Edmond
Edmond

Reputation: 644

How to change the url sent to an html form?

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

Upvotes: 7

Views: 9562

Answers (1)

laconbass
laconbass

Reputation: 17805

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

Upvotes: 4

Related Questions