The formEnctype
property sets or gets the formenctype attribute of a submit button.
The formenctype
attribute specifies how to encode form-data
during submitting for forms with method="post".
The formenctype
attribute from submit element
overrides the enctype attribute of the <form> element.
formEnctype |
Yes | 10.0 | Yes | Yes | Yes |
Return the formEnctype property.
var v = submitObject.formEnctype
Set the formEnctype property.
submitObject.formEnctype='application/x-www-form-urlencoded,multipart/form-data,text/plain'
Value | Description |
---|---|
application/x-www-form-urlencoded | Default. All characters are encoded before sent. |
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 the type of content that is used to submit the form to the server.
The following code shows how to change the value of the formenctype attribute of a submit button to "application/x-www-form-urlencoded".
<!DOCTYPE html>
<html>
<body>
<form action="demo_post_enctype.asp" method="post">
Name: <input type="text" name="fname" value="abc"><br>
<input type="submit" id="mySubmit" formenctype="text/plain" value="Submit">
</form><!-- w w w. j a v a 2 s. c om-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("mySubmit").formEnctype = "application/x-www-form-urlencoded";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get formenctype.
<!DOCTYPE html>
<html>
<body>
<!-- ww w. j a v a 2 s . c o m-->
<form action="demo_post_enctype.asp" method="post" enctype="application/x-www-form-urlencoded">
Name: <input type="text" name="fname" value="abc"><br>
<input type="submit" id="mySubmit" formenctype="text/plain" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySubmit").formEnctype;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: