Form action Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form


The action property sets or gets the action attribute in a form, which controls where to send the form data when a form is submitted.

Set the action property with the following Values

Value Description
URL Sets where to send the form data when the form is submitted.

Possible values:

  • An absolute URL - like action=""
  • A relative URL - like action="example.htm"

Return Value

A String, representing the URL of where to send the form-data when a form is submitted

The following code shows how to change the action URL of a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form id="myForm" action="nothing.asp">
  First name: <input type="text" name="fname" value="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br>
  <input type="submit" value="Submit">
</form>// w  ww  . ja  v a  2s .  c o m

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    document.getElementById("myForm").action = "#";
    document.getElementById("demo").innerHTML = "The value of the action attribute was changed to #.";


Related Tutorials