Latest web development tutorials

HTML DOM Form enctype attribute

Form Object Reference Form Object

Definition and Usage

enctype property sets or returns the MIME type used to encode the content of the form.

If the form does not enctype attribute, then when the text submitted default is "application / x-www-form-urlencoded".

When the input type is "file", the value is "multipart / form-data".

grammar

formObject.enctype=value

enctype attribute can have the following values:

描述
application/x-www-form-urlencoded 数据在发送前所有字符都会被编码 (默认)
multipart/form-data 没有字符被编码。这个值用于控制表单文件的上传
text/plain 空格转换为"+"符号,但没有特殊字符 编码


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support enctype attribute

Note: Internet Explorer and Safari browser returns "application / x-www-form -urlencoded", if no enctype attribute is defined (the default), other browsers no return value.


Examples

Examples

Return the form to launch the encoding type data server:

<html>
<body>

<form>
<form id="frm1" enctype="text/plain">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
</form>

<script>
document.write(document.getElementById("frm1").enctype);
</script>

</body>
</html>

Examples of the above output:

text/plain

try it"


Form Object Reference Form Object