Javascript DOM HTML Button formEnctype Property get

Introduction

Return how form-data should be encoded before sending it to a server:

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

Click button to get the value of the formenctype attribute of the submit button above.

The formenctype attribute overrides the HTML form's enctype attribute (application/x-www-form-urlencoded).

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page_binary.asp" method="post" enctype="application/x-www-form-urlencoded">
  Name: <input type="text" name="fname" value="css"><br>
  <button id="myBtn" type="submit" formenctype="text/plain">Submit</button>
</form>//from   www.  j  a  v  a  2 s .c  o m

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myBtn").formEnctype;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The formEnctype property sets or gets the value of the formenctype attribute of a button.

The formenctype attribute sets how form-data should be encoded before sending it to a server.

This attribute overrides the form's enctype attribute.

The formenctype attribute is only used for buttons with type="submit".

Property Values

Value Description
application/x-www-form-urlencoded Default. All characters are encoded before sent
multipart/form-data No characters are encoded. used for a file upload control
text/plainSpaces are converted to "+" symbols, but no special characters are encoded



PreviousNext

Related