
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to call a JavaScript function on a click event?
JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page.
When the page loads, it is called an event. When the user clicks a button, that clicks to is an event. Other examples include events like pressing any key, closing a window, resizing a window, etc.
The onclick() event occurs when a user clicks the left button of his mouse. Place your validation, warning etc., against this event type.
Example
You can try to run the following code to call a JavaScript function on a click event −
<html> <head> <script> <!-- function sayHello() { alert("Demo Alert") } //--> </script> </head> <body> <p>Click the following button and see result</p> <form> <input type="button" onclick="sayHello()" value="Click" /> </form> </body> </html
- Related Questions & Answers
- How to call a JavaScript function on click?
- How to call a JavaScript function from an onClick event?
- How to call a JavaScript function from an onsubmit event?
- How to call a JavaScript function from an onmouseover event?
- How to call a JavaScript function from an onmouseout event?
- How to call a JavaScript function on submit form?
- How can I trigger a JavaScript click event?
- How to draw a dot on a canvas on a click event in Tkinter Python?
- How to call a function in JavaScript?
- JavaScript Sum function on the click of a button
- How do I call a JavaScript function on page load?
- How to implement click event on toolbar icon?
- How can I download a file on a click event using selenium?
- How to call a Java function inside JavaScript Function?
- How to delay a JavaScript function call using JavaScript?
Advertisements