Posted by : Sudhir Chekuri Saturday, 26 October 2013

What is Javascript?

It is a light weight client side scripting language.
You can write javascript code in html page to convert static web page to dynamic page.
It is a case sensitive language ie., you cannot use lowercase letters incase of uppercase letters.
It is recommended to write javascript in head tag.
Javascript functions should be written inside <script> and </script>.
It is executed line by line by interpreter.
You can write javascript in external javascript file with .js as extension. You can call javascript functions written in external js file by adding the below tag in the html page.

<script src="external.js">  </script>

Using javascript we can change the properties of html elements, create html tags in runtime, change css styles in runtime.

Example javascript code in html file

<html>
<head>
<script language="javascript">
function f1()
{
alert('hi');
}
</script>
</head>
<body>
<input type="button" value="click me" onclick="f1()"/>
</body>

</html>

In the above code a button is created using html input button tag. It Clickme is the text displayed on the button. onclick is the event which calls javascript function f1 when user clicks on the button.
f1 function is written inside the script tag. alert box with hi message is displayed when user click on the button.

Example to call javascript function written in external js file

code in html file
<html>
<head>
<script src="external.js">
</script>
</head>
<body>
<input type="button" value="click me" onclick="f1()"/>
</body>

</html>

code in external.js file

function f1()
{
alert('hi');

}


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -