Urvik Goyani
Urvik Goyani

Reputation: 1

reset form not working

function resetForm() {
  document.getElementById('myForm').reset();
}
<div id="myForm">
  <label class="form ">First name:</label><br/>
  <input type="text" id="Fname" name="first name"></input><span id="first"></span><br>
  <label class="form ">last name:</label><br>
  <input type="text" id="Lname" name="last name"></input><span id="last"></span><br>enter code here
  <label class="form"> address:</label><br>
  <input type="text" id="Address" name="address name"></input> <span id="add"></span><br>
  <label class="form"> email:</label><br>
  <input type="text" id="Email" name="email name"></input> <span id="ema"></span><br>
  <label class="form"> gender:</label><br>
  <input type="radio" class="Gend" id="Male" value="male" name="Gender"><b><i>Male</i></b></input>
  <input type="radio" class="Gend" id="Female" value="female" name="Gender"><b><i>Female</i></b></input><span id="Ge"></span><br>
  <label class="form">Phone number:</label><br>
  <input type="text" id="Phone" name="phone"></input><span id="ph"></span><br><br>
  <input type="button" class="button " value="Submit" onclick="myFun()"></input>
  <input type="button" class="button " name="Save" value="Save" onclick="savedRow()" /><br>
  <input type="reset" class="button" name="Reset" value="reset" onclick="resetForm()" />
</div>

Upvotes: 0

Views: 58

Answers (3)

Harshal Yeole
Harshal Yeole

Reputation: 4993

You are using div instead of form. Just updated the first tag of your html code and voila it will start working.

Hope this solves your query.

function resetForm() {
  document.getElementById('myForm').reset();
}
<form id="myForm">
  <label class="form ">First name:</label><br/>
  <input type="text" id="Fname" name="first name"></input><span id="first"></span><br>
  <label class="form ">last name:</label><br>
  <input type="text" id="Lname" name="last name"></input><span id="last"></span><br>enter code here
  <label class="form"> address:</label><br>
  <input type="text" id="Address" name="address name"></input> <span id="add"></span><br>
  <label class="form"> email:</label><br>
  <input type="text" id="Email" name="email name"></input> <span id="ema"></span><br>
  <label class="form"> gender:</label><br>
  <input type="radio" class="Gend" id="Male" value="male" name="Gender"><b><i>Male</i></b></input>
  <input type="radio" class="Gend" id="Female" value="female" name="Gender"><b><i>Female</i></b></input><span id="Ge"></span><br>
  <label class="form">Phone number:</label><br>
  <input type="text" id="Phone" name="phone"></input><span id="ph"></span><br><br>
  <input type="button" class="button " value="Submit" onclick="myFun()"></input>
  <input type="button" class="button " name="Save" value="Save" onclick="savedRow()" /><br>
  <input type="reset" class="button" name="Reset" value="reset" onclick="resetForm()" />
</form>

Upvotes: 0

Zenoo
Zenoo

Reputation: 12880

The element you're targetting needs to be a <form> tag :

function resetForm() {
  document.getElementById('myForm').reset();
}
<form id="myForm">
  <label class="form ">First name:</label><br/>
  <input type="text" id="Fname" name="first name"></input><span id="first"></span><br>
  <label class="form ">last name:</label><br>
  <input type="text" id="Lname" name="last name"></input><span id="last"></span><br>enter code here
  <label class="form"> address:</label><br>
  <input type="text" id="Address" name="address name"></input> <span id="add"></span><br>
  <label class="form"> email:</label><br>
  <input type="text" id="Email" name="email name"></input> <span id="ema"></span><br>
  <label class="form"> gender:</label><br>
  <input type="radio" class="Gend" id="Male" value="male" name="Gender"><b><i>Male</i></b></input>
  <input type="radio" class="Gend" id="Female" value="female" name="Gender"><b><i>Female</i></b></input><span id="Ge"></span><br>
  <label class="form">Phone number:</label><br>
  <input type="text" id="Phone" name="phone"></input><span id="ph"></span><br><br>
  <input type="button" class="button " value="Submit" onclick="myFun()"></input>
  <input type="button" class="button " name="Save" value="Save" onclick="savedRow()" /><br>
  <input type="reset" class="button" name="Reset" value="reset" onclick="resetForm()" />
</form>

Upvotes: 0

LiefLayer
LiefLayer

Reputation: 1073

I think you need a form not a div just look this example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_form_reset

Upvotes: 1

Related Questions