Button formMethod attribute
Definition and usage
formMethod
Property setting or returning the button's formmethod attribute value.
The formmethod attribute specifies the HTTP method used to send form data. This attribute overrides the form's method attribute.
The formmethod attribute is only used for buttons with type="submit".
Form data can be sent as URL variables (using method="get") or as HTTP post (using method="post")
Notes on the "get" method:
- It appends form data in the form of name/value pairs to the URL
- This is very useful for form submissions where users want to bookmark the results
- The amount of data that can be placed in the URL is limited (varies by browser), so you cannot be sure that all form data will be transmitted correctly
- Do not use the "get" method to pass sensitive information! (Passwords or other sensitive information will be displayed in the browser's address bar)
Notes on the "post" method:
- It sends form data as an HTTP post transaction
- Form data submitted using the "post" method cannot be added to bookmarks
- More robust and secure than "get"
- No size limit
Note:formmethod attribute It is a new attribute of the <button> element in HTML5.
Instance
Example 1
Return the HTTP method used to send form data:
var x = document.getElementById("myBtn").formMethod;
Example 2
Change the method of sending form data:
document.getElementById("myBtn").formMethod = "post";
Example 3
Another example of returning the formMethod attribute:
var x = document.getElementById("myBtn").formMethod;
Syntax
Return the formMethod attribute:
buttonObject.formMethod
Set the formMethod attribute:
buttonObject.formMethod = get|post
attribute value
value | description |
---|---|
get | Ajouter les données du formulaire à l'URL : URL?name=value&name=value |
post | Envoyer les données du formulaire en tant que transaction HTTP post |
Détails techniques
Valeur de retour : | Valeur en chaîne, indiquant la méthode HTTP utilisée pour soumettre le formulaire au serveur. |
---|
Support du navigateur
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Pages associées
Manuel de référence HTML :L'attribut formmethod du <button> HTML