You are here: Reference > JavaScript > client-side > HTML DOM > properties > acceptCharset (form)

acceptCharset property (form)

Browser support:
Sets or retrieves a list of character encodings for a form.
By default, the character set of the form is the same as the character set of the entire document (you can set the character set of the document with the charset property of the meta tag).
If any element of the form contains characters that cannot be represented by the character set of the document, then you need to define the acceptCharset property.
When the form is submitted to a server, the browser uses the character set(s) to convert the text content of the form to a byte stream (the Content-Type HTTP header of the message will contain the used character encoding).
Use UTF-8 encoding on your site and in the database of your server to avoid internationalization problems.

Syntax:

object.acceptCharset;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: accept-charset

Possible values:

String that sets or retrieves a list of accepted character sets. The name of a character set is case-insensitive. The separator character between the character sets can be a space or a comma. For more information, see the page for character sets.
Default: UNKNOWN.

Example HTML code 1:

This example illustrates the use of the accept-charset attribute:
<form action="#URL#" method="post" accept-charset="UTF-8">
    User Name: <input type="text" name="userName" />
    <br />
    Password: <input type="password" name="password" />
    <br />
    <input type="submit" value="Sign in" />
</form>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the acceptCharset property:
<head>
    <script type="text/javascript">
        function GetAcceptedCharSet () {
            var form = document.getElementById ("myForm");
            alert ("The accepted character set by the form: " + form.acceptCharset);
        }
    </script>
</head>
<body>
    <form id="myForm" action="#URL#" method="post" accept-charset="UTF-8">
        User Name: <input type="text" name="userName" />
        <br />
        Password: <input type="password" name="password" />
        <br />
        <input type="submit" value="Sign in" />
    </form>
    <br />
    <button onclick="GetAcceptedCharSet ()">Get the accepted character set!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content