Javascript DOM HTML Form enctype Property get

Introduction

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

var x = document.getElementById("myForm").enctype;

Click button to display the value of the enctype attribute in the form element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page_binary.asp" method="post">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <input type="submit" value="Submit">
</form>/*from w w w .j  a  v  a2 s  .  com*/
<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 enctype property sets or gets the value of 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.

Property Values

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

The enctype property returns a String representing how form-data should be encoded before sending it to the server.




PreviousNext

Related