I going to shared simple JavaScript function for reset all form fields very easily.
JavaScript:

<script type=“text/javascript”>
function reset(){
  var demoObj = document.getElementsByClassName(“demo”);
  for(let i=0;i<demoObj.length;i++){
  //set blank for all input type field
  demoObj[i].value=””;
  if(demoObj[i].name===“A” || demoObj[i].name===“D”){
   //set default option value for A and B select box
   selected_log[i].options[0].selected=true;
  }
 }
}
</script>

HTML:

<html>
   <head>
   </head>
   <body>
      <form name=”swcodes_demo”>
        <input type=”text” name=”first_name” class=”demo” value=”hello”>
        <input type=”text” name=”last_name” class=”demo” value=”Bye”>
        <select name=”A”>
             <option value=“”>select</option>
             <option value=“all”>All</option>
             <option value=“one”>one</option>
             <option value=“two”>two</option>
        </select>
        <select name=”B”>
             <option value=“”>select</option>
             <option value=“male”>male</option>
             <option value=“female”>female</option>
        </select>
        <input type=”submit” name=”submit” value=”submit”>
        <input type=”button” name=”reset” value=”reset” onclick=”reset();”>
     </form>
  </body>
</html>

 

News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: