HTML | DOM Form acceptCharset Property

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.

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!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>

      chevron_right

      
      

      Output :

      Before Clicking On Button:

      After Clicking On Button:

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

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!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>

      chevron_right

      
      

      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
      • Internet Explorer
      • Firefox
      • Opera
      • Safari


      My Personal Notes arrow_drop_up

      Check out this Author's contributed articles.

      If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

      Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




      Article Tags :
      Practice Tags :


      Be the First to upvote.


      Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.