In this article, we will explore calling and initializing JavaScript functions from HTML templates. We need a JavaScript function to perform the required method on the passed input.
In this tutorial, we will discuss the two main methods of calling JavaScript functions from HTML pages.
In the first method, we will take a simple input tag and a submit button associated with it. After clicking the button, we will see a dialog box pop up on the screen as an alert. Clicking this button calls a JavaScript function to display the alert.
First, select a button next to the input tag.
After clicking the button, you can see A dialog box pops up on the screen that has been declared as an alert in a JavaScript function.
The clickEvent() function allows an alert() to be executed when this button is clicked using the onclick() method.
#index.html
<!DOCTYPE html> <html> <body> <h1 style="color: green;"> Welcome To Tutorials Point </h1> <input type="button" onclick="clickEvent();" value="Click Here !" /> <script> function clickEvent() { alert("Hey... The Javascript function is invoked."); } </script> </body> </html>
The above program will produce the following result. When you click the "Click here!" button it will alert and display the message "Hey...Javascript function called."
The above is the detailed content of How to call JavaScript functions in HTML?. For more information, please follow other related articles on the PHP Chinese website!