How to find the accept-charset and enctype attribute of a form in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Javascript has provided document.acceptCharset and document.enctype to get the accept-charset and enctype of a form. Let's discuss them individually.

Accept-Charset

Example

In the following example, a form has initially provided with an accept-charset and using the DOM property document.acceptCharset that accept-charset value is displayed as shown in the output.

Live Demo

<html>
<body>
<form id="form1" accept-charset="ISO-8800-7"></form>
<p id="char"></p>
<script>
   var cha = document.getElementById("form1").acceptCharset;
   document.getElementById("char").innerHTML = cha;
</script>
</body>
</html>

Output

ISO-8800-7


Enctype

Example

In the following example, the enctype of the form is displayed using document.enctype DOM command. There is no need to provide the value of enctype like name, target, etc.to the form. Any form will have an inbuilt enctype.

Live Demo

<html>
<body>
<form id="form1" name="form" action="/action_page.php"></form>
<p id="type"></p>
<script>
   var ty = document.getElementById("form1").enctype;
   document.getElementById("type").innerHTML = ty;
</script>
</body>
</html>

Output

application/x-www-form-urlencoded
raja
Published on 29-Jul-2019 14:23:48
Advertisements