Javascript DOM HTML Input Submit formAction Property set

Introduction

Change the URL for where to send the form-data:

document.getElementById("mySubmit").formAction = "/action_page2.php";

Click the button to change the value of the formaction attribute of the submit button.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form>
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <input type="submit" id="mySubmit" formaction="/action_page.php" value="Submit">
</form>//ww w . ja va  2  s.  c  o m
<p id="demo"></p>

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

<script>
function myFunction() {
  document.getElementById("mySubmit").formAction = "/action_page2.php";
  document.getElementById("demo").innerHTML = "The value of the formaction attribute was changed to 'action_page2.php'.";
}
</script>

</body>
</html>



PreviousNext

Related