The action
property sets or gets the action attribute in a form.
The action
attribute sets where to send the form data when a form is submitted.
action |
Yes | Yes | Yes | Yes | Yes |
Return the action property.
var v = formObject.action
Set the action property.
formObject.action=URL
Value | Description |
---|---|
URL | Set where to send the form data when the form is submitted. |
A String type value representing the URL of where to send the form-data when a form is submitted.
The following code shows how to get the URL for where to send the form data when a form is submitted.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j a v a 2 s . c om-->
<form id="myForm" action="url">
First name: <input type="text" name="fname" value="abc"><br>
Last name: <input type="text" name="lname" value="def"><br>
<input type="submit" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myForm").action;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the action URL of a form.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j a v a2 s.c o m-->
<form id="myForm" action="nothing.asp">
First name: <input type="text" name="fname" value="abc"><br>
Last name: <input type="text" name="lname" value="def"><br>
<input type="submit" value="Submit">
</form>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myForm").action = "url";
}
</script>
</body>
</html>
The code above is rendered as follows: