Basic Introduction to JavaScript

History of JavaScript

JavaScript was developed by Netscape under the name “Live Script”. These scripts were used to enhance the web pages by providing some HTML level interaction for the user. Later, live script was used as a communication medium between HTML documents and Java applets. In December 1995, Netscape and Sun joined hands and renamed the language as JavaScript.

Using JavaScript in and HTML page:-

JavaScript’s are written as part of HTML documents. The Browser software interprets the JavaScript commands just as it does with HTML tags. Browsers must be equipped with JavaScript interpreters to take advantage of the scripts in web pages but don’t get confused cause now days almost every browser is equipped with JavaScript interpreters or any Java compatible browser will also be able to interpret JavaScript scripts. JavaScript can be used in following situations:

  • Designing web page to respond to user interaction with form elements.
  • Importing and exporting data from databases and providing friendly interface to data.
  • Processing the data on the client side before submitting it to the server.

Adding JavaScript to an HTML page or in header:-

JavaScript can be inserted into HTML pages between <HEAD> and </HEAD> tags or <BODY> and </BODY> tags. JavaScript begins with a <SCRIPT> tag and ends with </SCRIPT> tag followed by <SCRIPT LANGUAGE=”JAVASCRIPT”> to identify the scripting language for the browser. The general structure of the JavaScript code in an HTML page is :

<SCRIPT language=”javascript”>
<!–
Statements
– ->
</SCRIPT>

Note the use of HTMl comment tags, <! – – and – ->.If the page containing the script is used in a browser that is not compatible with scripting languages. The script statements are not executed.

Using SRC attribute within

The SRC attribute allows us to load JavaScript from a separate file on the server. Eternal script files cannot contain HTML markup and must be saved as standard ASCII texts with .js extension. We can point to the script file using a relative URL such as

<SCRIPT language=”javascript” src=”myscript.js”>
</script>

We can also use absolute URL path such as:

<SCRIPT language=”javascript” src=”http://www.trueblogtips.com/myscript.js”>
</SCRIPT>

Comments are closed.