- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - enctype Attribute
The HTML enctype attribute is used to specify how the form input data should be encoded before sending it to the server.
This attribute is used if the value of the method attribute is post and is present within the <form> element. The default value of this attribute is "application/x-www-form-urlencoded".
Following are values of the ‘enctype’ attribute −
- text/plain − It is used for debugging purposes.
- multipart/form-data − It is used if the form contains the <input> element with type = file.
- application/x-www-form-urlencoded − It defines that all characters are encoded before being sent.
These values can be overridden by the formenctype attribute on <button>, <input type = submit>, or <input type = image> elements.
Syntax
Following is the syntax for HTML enctype attribute −
<form enctype = "value"></form>
Example
In the following example, we are using the HTML ‘enctype’ attribute with the value "text/plain" within the <form> element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'enctype' Attribute</title> <style> form { width: 300px; padding: 10px; border-radius: 10px; background-color: rgb(9, 109, 190); } form h1 { font-family: sans-serif; letter-spacing: 2px; color: white; text-align: center; position: relative; top: -20px; } form input { padding: 12px; width: 80%; border: 1px solid white; border-radius: 5px; outline: none; } form label { font-size: 20px; color: white; padding: 5px 5px; } form button { padding: 12px; width: 100px; cursor: pointer; background-color: white; border: 1px solid white; border-radius: 5px; } </style> </head> <body> <!--HTML 'enctype' attribute--> <h3>Example of the HTML 'enctype' attribute</h3> <p>We are assigning the "text/plain" value to the enctype attribute to convert the spaces to the "+" symbol, but no special characters are encoded.</p> <form action="index.js" enctype="text/plain" method="POST"> <h1>Login</h1> <label for="">Username</label> <br> <input type="text" id='uname' placeholder="Username"> <br> <br> <label for="">Password</label> <br> <input type="password" id='psw' placeholder="Password"> <br> <br> <button type='submit' onclick="Login()">Login</button> </form> <script src="index.js"></script> </body> </html>
index.js
function Login(){ var uname = document.getElementById("uname").value; var password = document.getElementById("psw").value; document.write("Usernamae" + uname); document.write("<br>"); document.write("Password: " + password); }
On executing the above script, the output window will pop up displaying the input field along with a login button on the webpage. whem the user submits the form rhe event gets triggered and displays the entered input data.
To Continue Learning Please Login
Login with Google