Friday, December 16, 2011

JavaScript Introduction

Web site development is not simply about 'designing', neither does it comprise of learning one language and excelling in it. Instead for good designs and better websites you need to get hands-on on several skills/tools/languates. For e.g. if you are working on ASP.Net, you'll need to know your way in and out of ASP.Net, then you'll need to know be proficient at a programming language like C# or VB.Net to do all the code-behind stuff.
In addition to that you'll need to have a good knowledge of Javascript and CSS. What are they? How are they used? What can be accomplished through them? etc.

(Of course there are a lot of other things involved in web site development, such as security, but let's keep that for another discussion.)

What is it? (What can be accomplished through it? and other similar questions)
First up Javascript and Java have nothing to do with each other, although the similarity in names is misleading.
To put simply, Javascript is used to add interactivity to web sites/pages. Using Javascript
  •     one can add HTML dynamically to the page, so that a piece of HTML is only included in the page when certain condition is true. For e.g. greeting message can be displayed based on the time of the day the page is viewed. (Good Morning, Good Afternoon etc.)
  •     to validate input before sending it to the server. As each request to server is time and resource consuming, it is considered smart to validate input before sending it to server.
How is it used?
Let's start working on JavaScript now.

The first step is to understand the ways through which JavaScript can be added to a web page.
There are two simple ways to do it:
  1. Include JavaScript in the page itself.
  2. Write JavaScript in a separate file and then include the file in the page (this method is beneficial whenever the same JavaScript needs to be used on multiple pages).

The script tag:

For implementing both the methods mentioned above, the script tag is used.
Usage: (Method # 1)
<script language = "JavaScript">
//JavaScript code

Usage: (Method # 2)

<script language = "JavaScript" scr = "filepath" />

The src (source) attribute expects a file path. The name of the file containing JavaScript MUST have the extension ".js".

Book: Java Script and Jscript by Jaworski

No comments:

Post a Comment