Javascript DOM HTML Input Submit formEnctype Property get

Introduction

Find out how form-data should be encoded before submitting it to a server:

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

Click the button to display the value of the formenctype attribute of the submit button.

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>
  <input type="submit" id="mySubmit" formenctype="text/plain" value="Submit">
</form>/*from www  .j  a  va  2s  .co  m*/
<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 formEnctype property sets or gets the value of the formenctype attribute of a submit button.

The formenctype attribute sets how form-data should be encoded when submitting it to the server.

The formenctype attribute overrides the enctype attribute of the <form> element.

Property Values

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

The formEnctype property returns a String representing the type of content that is used to submit the form to the server.




PreviousNext

Related