Javascript Reference - HTML DOM Form acceptCharset Property








The acceptCharset property sets or gets the accept-charset attribute in a form element.

The accept-charset attribute sets the character-sets for the form submission.

Browser Support

acceptCharset Yes Yes Yes Yes Yes

Syntax

Return the acceptCharset property.

var v = formObject.acceptCharset 

Set the acceptCharset property.

formObject.acceptCharset=character-set




Property Values

Value Description
character-set A space- or comma-separated list of character encodings.

Common values.

  • UTF-8
  • ISO-8859-1
  • ...

Return Value

A String type value representing the character sets for form submission.

Example

The following code shows how to change the accept-charset attribute in a form to UTF-8.


<!DOCTYPE html>
<html>
<body>
<!--  w ww .  j a v  a2  s  . c o m-->
<form id="myForm" accept-charset="ISO-8859-1">
  First name: <input type="text" name="fname" value="abc"><br>
  Last name: <input type="text" name="lname" value="def"><br>
</form>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myForm").acceptCharset = "UTF-8";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the character-set from a form.


<!DOCTYPE html>
<html>
<body>
<!--from  www  . j  a  v a 2s .  c  o m-->
<form id="myForm" accept-charset="ISO-8859-1">
  First name: <input type="text" name="fname" value="abc"><br>
  Last name: <input type="text" name="lname" value="def"><br>
</form>
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myForm").acceptCharset;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: