How to Call JavaScript Function on Click Events

This tutorial will help you to how to call a JavaScript function on click or submit events of various html controls.

Create JavaScript Function –

First, Create a JavaScript function like below and add this between <head>…</head> tag of your web page. You may also add function under separate JavaScript file and include in html page.


Now, Call above JavaScript function on Click events of various html controls. These HTML controls needs to put under <body> tag of web page.

1. On Hyper link Click

Add below HREF html code in body section and access on web browser. Now just click link, It will execute JavaScript’s myFunction which will show current date as per used above.


js-function-call-on-href

2. On Form Submit

Now call JavaScript function of form submit event. This is useful for validating form input values and then submit them.


js-function-call-on-submit-form

3. On Button Click

Now call JavaScript function of button click event.


js-function-call-on-button-click

4. On Link with P Tag

Now call JavaScript function link created using html “p” tag.


js-function-call-on-p-tag-click

Thanks for Visit Here

Comments