Javascript DOM HTML Form method Property get

Introduction

Return the method for sending form data:

var x = document.getElementById("myForm").method;

Click button to return the value of the method attribute in the form above.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php" method="get">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <input type="submit" value="Submit">
</form>/* w  w  w. j av a 2  s.  c o m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myForm").method;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related