In this tutorial, we will learn about Java Scripts.

Java Scripts are actually client side scripts. They are executed by the user’s browser and there is
nothing to do at the server-side unlike in case of php (Server Side Scripting).

For example, when you haven’t entered any of required field in a form while attempting to submit, instead of sending the entire user form data back to the server, developers would love to add a JavaScript that would actually perform basic checks/sometimes advanced mandatory checks and then the data is sent to the server for processing, in case if the user has not entered any detail, the user is asked to enter the required data using simple built-in JavaScript functions.

We will see how this is done.

At first, lets look at the JavaScript syntax.

<script type=”text/javascript”>
// Your JavaScript code is written here..
</script>

Every JavaScript that you write inside an html document should be placed between the <head> and </head>

A JavaScript can be written in a separate file as well, we will learn more about this a little later.

Lets write our first JavaScript..

Create a Simple HTML Button.

<input type =”button” value=”Click This Button”/>

There are several Built-in events defined, onclick is one such event.

We have to assign an event handler for this event. On occurrence of onclick the event handler is automatically called. This works in the same way as in most of the programming language.

event = eventhandler(). The event handler is actually defined in the JavaScript.

<input type =”button” value=”Click This Button” onclick=callmethod() />

The event handler is actually defined in the JavaScript. In the event handler you can define what should be done when you perform an event, in our case onclick

<script type=”text/Javascript”>
function callmethod()
{
document.write(“HELLO WORLD!!”);
}
</script>

The above script would simply print HELLO WORLD!! in the browser.

Complete code is given below.

<html>
<head>
<script type=”text/Javascript”>
function callmethod()
{
document.write(“HELLO WORLD!!”);
}
</script>
</head>

<body>

<input type =”button” value=”Click This Button” onclick=callmethod() />

</body>
</html>