Javascript DOM HTML Input Submit formMethod Property set

Introduction

Change the method for sending form-data:

document.getElementById("mySubmit").formMethod = "post";
<p>Click button to change the formmethod of the submit button in the form.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form target="_blank">
  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" formmethod="get" value="Submit">
</form>/*ww  w. ja  v a 2  s.c o m*/
<button onclick="myFunction()">Change formmethod</button>

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

<script>
function myFunction() {
  document.getElementById("mySubmit").formMethod = "post";
  document.getElementById("demo").innerHTML = "The formaction is now 'POST'.";
}
</script>

</body>
</html>



PreviousNext

Related