Wednesday, February 8, 2012

Day-1 : Introduction to Java Script

JavaScript is the scripting language. It developed by Netscape in 1995 as a method for validating forms and providing interactive content to web site. JavaScript works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. It is useful for client side scripting.  We must remember that Java and JavaScript are two completely different languages in both concept and design.

Few things of JavaScript:

  • JavaScript gives HTML designers a programming tool
  • JavaScript can react to events
  • JavaScript can read and write HTML elements
  • JavaScript can be used to validate data
  • JavaScript can be used to detect the visitor's browser
  • JavaScript can be used to create cookies
  • Developer depends on the browser support for the JavaScript
  • There is no way to hide the JavaScript code in case of commercial application

The javascript code will follow <SCRIPT language="JavaScript"> tag, and end with the </SCRIPT> tag:

<SCRIPT language="JavaScript">

........JavaScript Code...........


You can have as many <SCRIPT> tags as you need throughout the body of your HTML document.  Just remember to close each tag before you go on. If you are going to use JavaScript functions, you will need to place your functions inside the <HEAD> </HEAD> tags of your document. This way, your functions are loaded before the page begins to display, and you won't see all kinds of JavaScript errors.

Here is an example:



<SCRIPT language="JavaScript">
function cool ()
JavaScript Stuff...


Now, there is still one last thing you should see before we begin writing scripts. Since there are older browsers being used out there, they do not recognize the <SCRIPT> tag. Rather than performing your javascript, they will display the text of your script. To get around this problem, you have to trick the browser into ignoring the text within the <SCRIPT> tag. This is done by using an HTML comment. The older browsers will ignore the text inside the comments, but a JavaScript capable browser will go ahead and perform your script. Here is how to do it:

<SCRIPT language="JavaScript">

......Javascript Statements.......


1 comment: