Javascript DOM HTML Button formMethod Property set

Introduction

Change the method for sending form-data:

document.getElementById("myBtn").formMethod = "post";

Click the two buttons to change the formmethod of the submit button in the form.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php" target="_blank">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <button id="myBtn" formmethod="get"  type="submit">Submit</button>
</form>/*from  www  .j  av a  2s.  c o m*/

<button onclick="setGet()">GET</button>
<button onclick="setPost()">POST</button>

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

<script>
function setGet() {
  document.getElementById("myBtn").formMethod = "GET";
  document.getElementById("demo").innerHTML = "The formaction is now 'GET'.";
}

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

</body>
</html>



PreviousNext

Related