Open In App

HTML | DOM Form acceptCharset Property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Form acceptCharset Property is used to set or return the value of the accept-charset attribute in the form Element. The accept-charset attribute is used to define the character encoding and is used for form submission. The default value of the accept-charset attribute is “UNKNOWN” string which indicates the encoding equals to the encoding of the document containing the

element.

Syntax:

  • It is used to return the acceptCharset property.
    formObject.acceptCharset
  • It is used to set the acceptCharset property.
    formObject.acceptCharset = character-set
  • Property Values:

    • character-set : The attribute value contains the list separated value of one or more encoding attributes. The common value of encoding attributes are: UTF-8, ISO-8859-1. This attribute always associated with form element only.
    • Example-1: HTML Program that illustrate how to return the accept-charset Property.




      <!DOCTYPE html>
      <html>
        
      <head>
          <title>DOM Form accept-charset Property</title>
          <style>
              h1 {
                  color: green;
              }
                
              body {
                  text-align: center;
              }
          </style>
      </head>
        
      <body>
          <h1>GeeksforGeeks</h1>
          <h2>DOM Form accept-charset Property</h2>
          <form action="#"
                accept-charset="UTF-8"
                id="users">
              First name:
              
              <input type="text" 
                     name="fname">
              <br> Last name:
              
              <input type="text" 
                     name="lname">
              <br>
              
              <input type="submit" 
                     value="Submit">
          </form>
          
          <p><b>Click on "Try it" Button to return the 
            value of the accrpt-charset attribute.</b></p>
          
          <button onclick="myGeeks()">Try it</button>
          <p id="sudo" style="font-size:25px;color:green;">
        </p>
          
          <script>
              function myGeeks() {
                  
                  // Return accept-charset property
                  var x = document.getElementById(
                    "users").acceptCharset;
                  
                  document.getElementById(
                    "sudo").innerHTML = x;
              }
          </script>
      </body>
        
      </html>

      
      

      Output :

      Before Clicking On Button:

      After Clicking On Button:

      Example-2: HTML Program that illustrate how to set the accept-charset Property.




      <!DOCTYPE html>
      <html>
        
      <head>
          <title>DOM Form accept-charset Property
         </title>
          
          <style>
              h1 {
                  color: green;
              }
                
              body {
                  text-align: center;
              }
          </style>
      </head>
        
      <body>
          <h1>GeeksforGeeks</h1>
          <h2>DOM Form accept-charset Property
        </h2>
          
          <form action="#" 
                accept-charset="UTF-8" 
                id="users">
              First name:
              
              <input type="text" 
                     name="fname">
              <br> Last name:
              
              <input type="text"
                     name="lname">
              <br>
              
              <input type="submit" 
                     value="Submit">
          </form>
          
          <p><b>Click on "Try it" Button to set the 
            value of the accrpt-charset attribute.
            </b></p>
          
          <button onclick="myGeeks()">
            Try it
        </button>
          
          <p id="sudo"
             style="font-size:25px;color:green;">
        </p>
          
          <script>
              function myGeeks() {
                  
                 // Set acceptCharset property.
                  var x = document.getElementById(
                    "users").acceptCharset = "ISO-8859-1";
                  
                  
                  document.getElementById("sudo").innerHTML =
                 "The value of the accept-charset attribute"
                  " was changed to " + "<br>" + x;
              }
          </script>
      </body>
        
      </html>

      
      

      Output:

      Before Clicking On Button:

      After Clicking On Button:

      Supported Browsers: The browser supported by DOM Form accept-charset Property are listed below:

      • Google Chrome 1 and above
      • Edge 12 and above
      • Firefox 1 and above
      • Opera 12.1 and above
      • Safari 3 and above


      Last Updated : 31 Aug, 2022
      Like Article
      Save Article
      Previous
      Next
      Share your thoughts in the comments
Similar Reads