HTML | DOM Form action Property

The Form action property in HTML DOM is used to set or return the value of the action attribute of the Form. After submission of form the action attribute called. The form data is to be sent to the server after submission of form.

Syntax:

  • It is used to return the action property.
    formObject.action
  • It is used to set the action property.
    formObject.action = URL
  • Property Values:



    • URL: It is used to specify the URL of the document where the data to be sent after submission of form.
      The possible value of URL are:

      • absolute URL: It points to another website link . For Example: www.gfg.org
      • relative URL: It is used to point to a file within in a webpage. For Example: www.geeksforgeeks.org

    Return Value: It returns a string value which represent the URL of the form.

    Example 1: This example describes how to set action property.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
      
    <head>
        <title>
            HTML DOM Form action Property
        </title>
    </head>
      
    <body
        <h1>GeeksforGeeks</h1>
          
        <h2>DOM Form action Property</h2>
          
        <form action="#" method="post" id="users"
          
            <label for="username">Username:</label
            <input type="text" name="username" id="Username">
              
            <br><br>
              
            <label for="password">Paswword :</label>
            <input type="password" name="password">
        </form>
          
        <br>
          
        <button onclick = "myGeeks()">
            Submit
        </button
          
        <p id = "GFG"></p>
          
        <!-- script to set action page -->
        <script>
        function myGeeks() {
            var x = document.getElementById("users").action
                    = "/gfg.php";
                      
            document.getElementById("GFG").innerHTML
                = "Action page Changed";
        }
        </script>
    </body
      
    </html>                    

    chevron_right

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

    Example 2: This example returns the action property.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
      
    <head>
        <title>
            HTML DOM Form action Property
        </title>
    </head>
      
    <body
        <h1>GeeksforGeeks</h1>
          
        <h2>DOM Form action Property</h2>
          
        <form action="test.php" method="post" id="users"
          
            <label for="username">Username:</label
            <input type="text" name="username" id="Username">
              
            <br><br>
              
            <label for="password">Paswword :</label>
            <input type="password" name="password">
        </form>
          
        <br>
          
        <button onclick="myGeeks()">
            Submit
        </button
          
        <p id = "GFG"></p>
          
        <!-- script to return the the URL where 
                send the form data -->
        <script>
            function myGeeks() {
                var act = document.getElementById("users").action;
                document.getElementById("GFG").innerHTML = act;
            }
        </script>
    </body
      
    </html>                    

    chevron_right

    
    

    Output:
    Before Click on the Button:

    After Click on the Button:

    Supported Browsers: The browser supported by DOM Form action 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.