Java script :
JavaScript is a most popular programming language. It is the language for websites and implemented as part of web browsers, so why it is called client side script.
Facts about Javascript :
* Javascript is a lightweight client side scripting language.
* JavaScript inserted into HTML pages, can be executed by all modern web browsers.
* JavaScript is an interpreted language. The scripts execute without preliminary compilation.
* Open and cross-platform.
You can use it to make your web pages interactive by :
* Responding to user actions and changes on the page.
* Manipulating the web page's contents and behavior.
* Communicating with the user directly
How/Where to place It :
Since javascript isn't HTML, you will need to let the browser know in advance when you enter javascript to an HTML page. This is done using the <script> tag. The browser will use the <script type="text/javascript"> and </script> to tell where javascript starts and ends.
You can enter javascript in both the <head> and <body> sections of the document.
In general however, it is advisable to keep as much as possible in the <head>section.
Example :
<html>
<head>
<title>My Javascript Page</title>
</head>
<body>
<script type="text/javascript">
document.write("Welcome to my world!!!");
</script>
</body>
</html>
Output :
Welcome to my world!!!
Embedding JS in HTML :
Inline JS
Example :
Problems with inline JavaScript :
* You have to write your code out in full for every button. (Example given here is very very simple, but it could be much more complicated when it required more than one line and complex in logic.)
* That means if you have more than one button then it increases complexity, and if you want to change, you have to locate and edit every occurrence of the code.
* It makes your pages longer, more cluttered and more complex. A better way to manage your code is to put it in separate functions in the same HTML file.
Internal JS
External JS