Javascript DOM HTML Button type Property change to "reset"

Introduction

Change the type of a button to "reset":

document.getElementById("myBtn").type = "reset";

Try to write something in the form, and then press "Reset".

The "Reset" button will not reset the form, because of the button type.

Click the button below to change the type of the "Reset" button from "button" to "reset".

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button id="myBtn" type="button" value="Reset">Reset</button>
</form>// w w  w.j  a v a2s  . c  o m

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

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

<script>
function myFunction() {
  var x = document.getElementById("myBtn").type = "reset";
  document.getElementById("demo").innerHTML = "The 'Reset' button now works as it should.";
}
</script>

</body>
</html>



PreviousNext

Related