title: Clear form after submission in JavaScript
body: <p>I see this has been asked multiple times but after trying all different combinations, I'm still unable to clear form upon submission.</p>
  
  <p>I'm just a beginner in HTML and JS so my code is a bit incoherent and not very well indented. </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;style&gt;
  body{ background-color:powderblue;}
  h1{text-align:center}
  h1{color:purple;}
  &lt;/style&gt;
  &lt;h1&gt;Fill up the details&lt;/h1&gt;
  &lt;form name="myform"&gt;
  Name:    &lt;input type="text" value="" name="name"\&gt;
  &lt;br&gt;
  &lt;br&gt;
  Class: &lt;input type="text" value="" &gt;&lt;/td&gt;
  &lt;br&gt;
  &lt;br&gt;
  Register No.: &lt;input type="number" value="" &gt;
  &lt;br&gt;
  &lt;br&gt;
  Username:    &lt;input type="text" value="" name="username"\&gt;
  &lt;br&gt;
  &lt;br&gt;
  Password:    &lt;input type="password" value="" name="password1"\&gt;
  &lt;br&gt;
  &lt;br&gt;
  Re-enter Password:    &lt;input type="password" value="" name="password2"\&gt;
  &lt;br&gt;
  &lt;br&gt;
  Mobile No.: &lt;input type="number" value="" \&gt;
  &lt;br&gt;
  &lt;br&gt;
  Email: &lt;input type="text" value="" \&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  function show_alert()
  {  
  var name=document.myform.name.value;  
  var password1=document.myform.password1.value;  
  var password2=document.myform.password2.value; 
  if (name==null || name=="")
  {  
  alert("Name can't be blank");  
  
  }
  else if(password1!=password2)
  {  
  alert("password must be same!");  
  return false;  
  }  
  else if(password1.length&lt;6)
  {  
  alert("Password must be at least 6 characters long.");  
  return false;  
  } 
  else 
  {
  alert("Your account has been created!!!!!");
  return false;
  }
  function reset()
  {
  var form=document.getElementById("myform");
  form.reset();
  alert("Form has been reset.");
  }
  }
  &lt;/script&gt;
  &lt;input type="button" value="Submit" onclick="show_alert()"/&gt;
  &lt;input type="button" value="Reset" onclick="reset()"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>