Button formMethod attribute

Definition and usage

formMethod Attribute that sets or returns the 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")

Points to consider about 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)

Points to consider about the "post" method:

  • It sends form data as an HTTP post transaction
  • Form data sent using the "post" method cannot be bookmarked
  • More robust and secure than "get"
  • No size limit

Note:formmethod attribute It is a new attribute of the <button> element in HTML5.

Example

Example 1

Return the HTTP method used to send form data:

var x = document.getElementById("myBtn").formMethod;

Try it yourself

Example 2

Change the method of sending form data:

document.getElementById("myBtn").formMethod = "post";

Try it yourself

Example 3

Another example of returning the formMethod attribute:

var x = document.getElementById("myBtn").formMethod;

Try it yourself

Syntax

Return the formMethod attribute:

buttonObject.formMethod

Set the formMethod attribute:

buttonObject.formMethod = get|post

attribute value

value description
get Προσθήκη δεδομένων φόρμουλας στην URL: URL?name=value&name=value
post Αποστολή των δεδομένων του φόρμουλας ως HTTP post γεγονός

Τεχνικά λεπτομέρειες

Αποτελεσματικότητα: Αριθμητική τιμή, που δείχνει την HTTP μέθοδο που χρησιμοποιείται για την υποβολή του φόρμουλας στο διακομιστή.

Υποστήριξη περιηγητή

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Υποστήριξη 10.0 Υποστήριξη Υποστήριξη Υποστήριξη

Σχετικές σελίδες

Εγχειρίδιο HTML:HTML <button> περιπτώσεις formmethod