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.
acceptCharset |
Yes | Yes | Yes | Yes | Yes |
Return the acceptCharset property.
var v = formObject.acceptCharset
Set the acceptCharset property.
formObject.acceptCharset=character-set
Value | Description |
---|---|
character-set | A space- or comma-separated list of character encodings. Common values.
|
A String type value representing the character sets for form submission.
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:
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: