Form enctype attribute

Definition and Usage

enctype Sets or returns the value of the enctype attribute in the form.

The HTML enctype attribute specifies how form data should be encoded before being sent to the server.

By default, form data is encoded as "application/x-www-form-urlencoded". This means that all characters are encoded before being sent to the server (spaces are converted to "+" symbols, and special characters are converted to ASCII HEX values).

See also:

HTML Reference Manual:Proprietà enctype dell'<form> HTML

Example

Example 1

Return how the form data should be encoded before it is sent to the server:

var x = document.getElementById("myForm").enctype;

Try it yourself

Example 2

Change the enctype value, setting how the form data should be encoded before it is sent to the server:

document.getElementById("myForm").enctype = "multipart/form-data";

Try it yourself

Syntax

Return the enctype attribute:

formObject.enctype

Set the enctype attribute:

formObject.enctype = "application/x-www-form-urlencoded,multipart/form-data,text/plain"

Attribute value

Value Description
application/x-www-form-urlencoded All characters are encoded before sending (default).
multipart/form-data Nessun carattere viene codificato. Questo valore è obbligatorio quando si utilizza un modulo con controlli di caricamento di file.
text/plain Gli spazi vengono convertiti nel simbolo "+", ma non vengono codificati i caratteri speciali.

Dettagli tecnici

Valore di ritorno: Valore di stringa che indica come codificare i dati del modulo prima di inviarli al server.

Supporto dei browser

I numeri nella tabella indicano la versione del browser che supporta completamente l'attributo.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supporto Supporto Supporto Supporto Supporto