1) Script in the
<head> tags of the HTML page.
2) Script in the
<body> tags of the HTML page.
3) Script in
both the and the tags of the HTML page.
Let us discuss each part in more detail.
Part 1: Script in the
Let us say that you want have a button in the webpage. When a user clicks the button, it must do something and perform certain task. Such kind of behavior is called event. Let us take a simple example.
Step 1: Create the html document, just like the one you have created in the previous level. It would look something like this:
Step 2: Create the button in the tag of HTML. As button creation is in the domain of HTML programming, so I hope you have some know-how of HTML language. The code now will look like this:
As you can see the
<input> tag has three attributes: type, onClick, and value. Value is the text of the button. onClick is the function call. I shall talk about the function-call in the latter levels. Type is the type of the input, which in this case is in button.
Part 2: Script in the
<body> of HTML code.
Part 3: Script in both
<body> tags of HTML. The example below illustrates it.
Just copy the above code and save it as an HTML file, and run it on your favorite browser.