Open In App

HTML DOM Form action Property

The HTML DOM Form action property allows accessing and modifying the action attribute of a form element through JavaScript. It determines the URL where form data is submitted when the form is submitted.

Syntax:



Property Values:

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



HTML DOM Form action Property Examples

Example: This example describes how to set action property.




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Form action Property
    </title>
</head>
 
<body>    
    <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>

Output:

HTML DOM FORM Action Property

Explanation:

Example 2: This example returns the action property.




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Form action Property
    </title>
</head>
 
<body>
 
    <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>

Output:

HTML DOM Form Action Property Example

Explanation:

HTML DOM Form action Property Use Cases

1.How to use formaction attribute in HTML ?

The formaction attribute specifies the URL where to send the form-data when the form is submitted. It overrides the action attribute of the <form> element for a specific button.

2.What does the action attribute do in HTML Form Tag ?

The action attribute in the HTML <form> tag specifies the URL where the form data should be sent upon submission, directing the browser to the designated endpoint for processing.

HTML DOM Form action Property Supported Browsers

The browser supported by DOM Form action property are listed below:


Article Tags :