Sunday 22 June 2014

Introduction to Javascript

  JavaScript is the most popular programming language in the world.
  It is the language for HTML, for the Web, for computers, servers, laptops, tablets, smart phones, and more.
JavaScript is:
  JavaScript is a lightweight, interpreted programming language
  Designed for creating network-centric applications
  Complementary to and integrated with Java
  Complementary to and integrated with HTML

  Open and cross-platform

Advantages of JavaScript:

  The merits of using JavaScript are:
  Less server interaction: You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
  Immediate feedback to the visitors: They don't have to wait for a page reload to see if they have forgotten to enter something.
  Increased interactivity: You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
  Richer interfaces: You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.

 Syntax of JavaScript:-

  A JavaScript consists of JavaScript statements that are placed within the <script>... </script> HTML tags in a web page.
  You can place the <script> tag containing your JavaScript anywhere within you web page but it is preferred way to keep it within the <head> tags.
  The <script> tag alert the browser program to begin interpreting all the text between these tags as a script. So simple syntax of your JavaScript will be as follows
SYNTAX:-
                                                <script ...> JavaScript code </script>

Attributes used in Javascript:-

The script tag takes two important attributes:
  language: This attribute specifies what scripting language you are using. Typically, its value will be javascript. Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.
  type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to “ text/javaScript ".
 
                                <script language="javascript" type="text/javascript">
                                                                 JavaScript code
                                </script>


 Example:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>JAVASCRIPT</title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
   document.write("Hello World!")
//-->
</script>
</body>
</html>