Hi,
How to count the number of times a button is clicked using JavaScript?
When the button is clicked the count will be incremented.
Hi makenzi.exc,
Refer below example.
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <input id="btnSubmit" type="button" value="Submit" onclick="GetClickCount()" /> <br /> <span id="lblMessage"></span> <script type="text/javascript"> var clicks = 0; function GetClickCount() { clicks += 1; document.getElementById("lblMessage").innerHTML = clicks + " times Button is clicked."; }; </script> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.