Button formEnctype Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Description

The formEnctype property sets or gets the formenctype attribute of a button, which controls how form-data should be encoded before sending it to a server.

This attribute overrides the form's enctype attribute, which is only used for buttons with type="submit".

Set the formEnctype property with the following Values

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

Return Value

A String, representing the type of content that is used to submit the form to the server

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page_binary.asp" method="post">
Name: <input type="text" name="fname" value="your name"><br>
<button type="submit">Submit with character encoding</button>
<button id="myBtn" type="submit" formenctype="text/plain">Submit without character encoding</button>
</form>//from  ww  w.  j a v a  2s  .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>

Related Tutorials