4.1 Javascript
JavaScript is a scripting language (a lightweight programming language) that was designed to add interactivity to HTML pages. It can be embedded directly into HTML web pages or can be kept as a seperate file with the extension .js that can then be linked to from a HTML file. Note that Javascript (real name ECMAScript) is completely different to Java, a language like C++ developed by Sun Microsystems. Javascript adds functionality to websites, such as validating forms, detecting browsers, and much more - I've even used it for adding falling snow to a client's website at Xmas!
Javascript will normally execute immediately on page load or can be made to execute at a later event (such as when a visitor clicks a button). Again a simple text editor such as Microsoft Notepad can be used and Javascript can be placed directly into web pages either in the body section or in the head section, or kept as a seperate file altogether that is then linked to from the head section of the HTML page.
Javascript can be placed into HTML documents by using the <script> tag and type attribute, like this:
<html> <body> <script type="text/javascript"> document.write("Hello World!"); </script> </body> </html>
The simple piece of Javascript between the script tags would result in a browser displaying the words "Hello World!". To link to an external Javascript file, we simply need to add the src attribute too like this:
<html> <head> <script type="text/javascript" src="time.js"></script> </head>
This would link the HTML document to Javascript file called "time.js".
JavaScript has a pretty simple syntax, meaning it is quite easy to put small snippets of this code into HTML pages. There are many places on the Internet where you can search for a snippet to suit whatever task you require. Jvascript can be used for many purposed, from putting dynamic text into pages, reacting to events such as user clicking, reading and writing HTML elements, validating data, detecting visitors' browser versions, and even creating cookies (a file that retrieves and stores information on visitors' computers.