What is JavaScript? |
JavaScript is Netscape's cross-platform, object-based
scripting language. It is not useful as a standalone language. It can be
embed with a HTML file to give an interaction to the web pages. JavaScript
can also be thought of as an extension to HTML. The JavaScript is
interpreted by the client web browser and solve our purpose.
By
using JavaScript, we can customize our web pages on the fly, write event
handlers, validate data at the client-side and perform other client-side
computation. JavaScript brings interaction to the web pages.
For
example, when a user press the SUBMIT button in a html form, if we want to
check the value of a mandatory text field, we no need make a server call
for this purpose initially. If it is something simple, we can do the
validation locally, ie., in the client-side itself using JavaScript and
give an alert to the user asking him to enter a value in that field.
JavaScript can also be used in a number of ways to spice up our
page.
Now-a-days, almost all the web applications needs this type
scripts, for various purpose. There are few scripts of this kind. The one
more is VBScript by Microsoft. But JavaScript is one widely used. The
advantage of JavaScript over other scripting languages of this kind will
be explained in due course.
The current version of JavaScript is 1.5.
|
|
Is it Java or how it is related to Java? |
JavaScript and Java are similar in some ways but
fundamentally different in others. The JavaScript language resembles Java
but does not have Java's static typing and strong type checking.
JavaScript supports most Java expression syntax and basic control-flow
constructs. |
|
What should I know to learn JavaScript? |
Some basic HTML is enough. The knowledge of any programming
language, will make the understanding easier. But, it is not a must.
Nothing to worry. |
|
What are the softwares I need to install for JavaScript? |
Nothing more than
- a latest web browser which supports JavaScript. All most all the
latest web browsers supports JavaScript. The minimum is Netscape 3 or
IE4. (IE3.02 supports JavaScript but not all the functions will wok.)
and
- a basic text editor.
|
|
Something more about JavaScript. |
- JavaScript is case sensitive.
- JavaScript is divided into two as client-side and server-side
JavaScript.
- Out of these two sections, only the client-side JavaScript is widely
used.Even the server-side JavaScript having its own features, there are
more popular and advanced server-side scripts, like Servlet, Java Server
Page(JSP), Active Server Page (ASP), are available.
- The scope of this document is to tell about client-side JavaScript.
|
|
What is the basic structure of JavaScript? |
<SCRIPT language="JavaScript">
... JavaScript Code ...
</SCRIPT>
Also can also specify an external JavaScript file as,
<SCRIPT language="JavaScript" src="myJavaScript.js"></SCRIPT>
- You can have as many <SCRIPT> tags as you like.
- Close the first one before start the new one.
|
Where to place my JavaScript in a html? |
Anywhere in the html. But the recommended place is inside
the <HEAD> </HEAD> tags of your html. This way, your functions
are loaded before the page begins to display, and you won't see all kinds
of JavaScript errors.
Example:
<HTML>
<HEAD>
<TITLE>My Title</TITLE>
<SCRIPT language="JavaScript">
function cool() {
.......
}
</SCRIPT>
</HEAD>
Here, you may ask me, what will happen if suppose somebody
use some old browsers? The answer is, if the old browser don't recognize
the tag <SCRIPT> and rather than performing your JavaScript, they
will display your script as text in the browser. OK. Then how to avoid
this? See the following:
<SCRIPT language="JavaScript">
<!-- Hide from older browsers
...... JavaScript Statements .......
// end hiding-->
</SCRIPT>
Before start programming, we see some examples in the examples page.
|