Form enctype Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form

Description

The enctype property sets or gets the enctype attribute in a form, which controls 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.

Set the enctype property with the following Values

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

Return Value

A String, representing how form-data should be encoded before sending it to the server

The following code shows how to return how form-data should be encoded before sending it to the server:

Demo Code

ResultView the demo 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="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br>
  <input type="submit" value="Submit">
</form>//from   w  w w. j av a 2s. c  o  m

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

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

<script>
function myFunction() {
    var v = document.getElementById("myForm").enctype;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials