
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- 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
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Form acceptCharset Property
The HTML DOM Form acceptCharset property is associated with the accept-Charset attribute of the <form> element. This property is used for setting and getting the accept-Charset attribute value of a form. It returns the character encoding in the string type.
If accept-Charset value is not specified it will return UNKNOWN which indicate that the character encoding is set to the character encoding of the current HTML document.
Syntax
Following is the syntax for −
Setting the acceptCharset property −
formObject.acceptCharset = character-set
Here, the character-set is the list separated by semicolon or space indicating one or more of the character encoding value. Some of the most commonly used values are UTF-8 and ISO-8859-1.
Example
Let us look at an example for the Form acceptCharset property −
<!DOCTYPE html> <html> <head> <style> form{ border:2px solid blue; margin:2px; padding:4px; } </style> <script> function changeEnc() { document.getElementById("FORM1").acceptCharset = "ISO-8859-1"; document.getElementById("Sample").innerHTML = "The character set is now ISO-8859-1 instead of UTF-8 for this form"; } </script> </head> <body> <form id="FORM1" accept-charset="UTF-8"> <label>User Name <input type="text" name="usrN"></label><br><br> <label>Password <input type="password" name="pass"></label> </form> <p>Change the charset encoding for the form element from UTF-8 to ISO-8859-1 by clicking the below button<p> <button onclick="changeEnc()">CHANGE</button> <p id="Sample"></p> </body> </html>
Output
This will produce the following output −
On clicking the CHANGE button −
In the above example −
We have created a form with id “FORM1” and acceptCharset property value to “ISO-88591”. This form contain an input field with type text and another one with type password −
<form id="FORM1" accept-charset="UTF-8"> <label>User Name <input type="text" name="usrN"></label> <br><br> <label>Password <input type="password" name="pass"></label> </form>
We have then created a button CHANGE that will execute the changeEnc() method when clicked by the user −
<button onclick="changeEnc()">CHANGE</button>
The changeEnc() function gets the <form> element using the getElementById() method. It then sets its acceptCharset property value to “ISO-8859-1” which is latin character encoding. We then display a message in paragraph with id “Sample” using its innerHTML property to display the text regarding this change−
function changeEnc() { document.getElementById("FORM1").acceptCharset = "ISO-8859-1"; document.getElementById("Sample").innerHTML = "The character set is now ISO-8859-1 instead of UTF-8 for this form"; }
- Related Articles
- HTML DOM Object form Property
- HTML DOM Legend form Property
- HTML DOM Textarea form Property
- HTML DOM Form name Property
- HTML DOM Fieldset form property
- HTML DOM Form action Property
- HTML DOM Form autocomplete Property
- HTML DOM Form enctype Property
- HTML DOM Form length Property
- HTML DOM Form method Property
- HTML DOM Form target property
- HTML DOM Select form Property
- HTML DOM Input URL form Property
- HTML DOM Input Week form Property
- HTML DOM Input Password form Property
