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

<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
  if(demoObj[i].name===“A” || demoObj[i].name===“D”){
   //set default option value for A and B select box


      <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 name=”B”>
             <option value=“”>select</option>
             <option value=“male”>male</option>
             <option value=“female”>female</option>
        <input type=”submit” name=”submit” value=”submit”>
        <input type=”button” name=”reset” value=”reset” onclick=”reset();”>


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 *