Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why did my onclick attribute in input type button is not working?

Here is My code

    <form name="formA">
      <input type="text" name="iptA" id="iptA" value="" />
      <input type="button" name="btnA" id="btnA" value="Click Here" onclick="count();"/>
      <input type="button" name="btnClr" id="btnClr" value="Clear" onclick="clear();"/>
      
    </form>
    <script type="text/javascript" charset="utf-8">
      var a = 0;
      document.formA.iptA.value = a;
      function count(){
        a++;
        document.formA.iptA.value = a;
      }
      
      function clear(){
        a = 0;
        document.formA.iptA.value = a;
      }
    </script>

In this, the function count() is working properly but the second function clear() is not working.

Thanks in advance 😊

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Rename clear to foo and it will work. clear already has a meaning in browser pov – clearing the console

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading