
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML enctype Attribute
The HTML enctype attribute specifies the encode format for form data. When post method is used then the enctype attribute can be specified.
Here, enctype attribute can have the following values −
Value | Description |
---|---|
application/x-www-form-urlencoded | It is the default value. All characters are encoded before they are sent (spaces are converted to "+" symbols, and special characters are converted to ASCII HEX values) |
multipart/form-data | It does not encodes characters. This value is required if user is using forms that have a file upload control |
text/plain | With this value of enctype spaces are converted to "+" symbols, but no special characters are encoded |
Let us see an example of HTML enctype property:
Example
<!DOCTYPE html> <html> <head> <title>HTML enctype attribute</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form enctype="multipart/form-data" action="" method="post"> <fieldset> <legend>HTML-enctype-attribute</legend> <label for="EmailSelect">Email Id: <input type="email" id="EmailSelect"> <input type="button" onclick="getUserEmail('david')" value="David"> <input type="button" onclick="getUserEmail('shasha')" value="Shasha"><br> <input type="button" onclick="login()" value="Login"> </label> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputEmail = document.getElementById("EmailSelect"); function getUserEmail(userName) { if(userName === 'david') inputEmail.value = 'davidMiller@MNC.com'; else inputEmail.value = 'shashaGreen@MNC.com'; } function login() { if(inputEmail.value !== '') divDisplay.textContent = 'Successful Login. Hello '+inputEmail.value.split("@")[0]; else divDisplay.textContent = 'Enter Email Id'; } </script> </body> </html>
Output
This will produce the following output −
1) Clicking ‘Login’ button with empty email field −
2) After clicking ‘Login’ button with email field set −
- Related Questions & Answers
- HTML DOM Form enctype Property
- How to find the accept-charset and enctype attribute of a form in JavaScript?
- HTML accept Attribute
- HTML accesskey Attribute
- HTML autofocus Attribute
- HTML checked Attribute
- HTML Class Attribute
- HTML cols Attribute
- HTML colspan Attribute
- HTML content Attribute
- HTML contenteditable Attribute
- HTML data Attribute
- HTML dir Attribute
- HTML disabled Attribute
- HTML for Attribute
Advertisements