The enctype
property sets or gets the enctype attribute in a form.
The enctype
attribute sets
how form-data should be encoded before sending it to the server.
The form-data is encoded to "application/x-www-form-urlencoded" by default. All characters are encoded before they are sent to the server.
enctype |
Yes | Yes | Yes | Yes | Yes |
Return the enctype property.
var v = formObject.enctype
Set the enctype property.
formObject.enctype='application/x-www-form-urlencoded|multipart/form-data|text/plain'
Value | Description |
---|---|
application/x-www-form-urlencoded | All characters are encoded before sent. This is default. |
multipart/form-data | No characters are encoded. This value is required for a file upload control |
text/plain | Spaces are converted to '+' symbols, but no special characters are encoded |
A String type value representing how form-data should be encoded before sending it to the server.
The following code shows how to change the enctype value.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . ja v a 2s . co m-->
<form id="myForm" action="demo_post_enctype.asp" method="post">
First name: <input type="text" name="fname" value="abc"><br>
<input type="submit" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myForm").enctype = "multipart/form-data";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get enctype for a form.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j ava 2 s . c o m-->
<form id="myForm" action="demo_post_enctype.asp" method="post">
First name: <input type="text" name="fname" value="abc"><br>
<input type="submit" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myForm").enctype;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: