What is Javascript??
-->It is a scripting language for the web.
-->It is used to handle events on the client side.
-->Is used to obtain browser information.
-->Uses AJAX fro retrieving information from the server without page reload.
-->Enables Animation and Timers Creation and setting.
Javascript includes three categories
-->Core
-->Server Side
-->DOM objects..
You start with javascript core and all other 2 will cover it up..
The HTML <script> tag is used to include a script into the html page and id is used to uniquely identify the elements.
<script type="text/javascript" src="js1.js">
You can either have the js file in the body or in the head or in another External file.
Variable declarations:
You need not specify any type in general.Just give it as
var name="blabla";
You can define functions using
function fname(arguments)
{
function bodyl;
}
Now if you want to invoke this onmouseOver give it as onMouseOver="fname()"
and the function body will be executed on that event.
Events can also be onMOuseclick,onKeyStroke,onMousedblClick etc.
An eg code to change text on mouseover:
To access a particular element in the HTml document use its unique Id.For eg if u have a paragraph with id="sin1"
then to get its value give it as
String s1=document.getElementById("sin1");
This uses the DOM structure to access the element "sin1" from the whole HTML document.
Arrays in javascript can be just given as
var e=[[[1,2,3],[5,6,7]][[5,4,6][8,7,9]];
Any dimensional array can be declared in javascript just by using "var".There are no specific types..
Date function
This is used to calculate the Date.
var d=new Date();
//gives the current date..
You can obtain the current date in millisec by using .getTime function.
You can get the current time in milliseconds using ".getmilliseconds" of the Date object.There are numerous other objects which the date's object can access.
LOOPS:
The for loop ,while loop and the "if" construct can be used as in the normal programming language."For" can also be used as below to traverse through an array..
for(x in array_name)
{
alert(array_name[x]);
}
Inbuilt Objects:
-->Math is and object which can access members like pi,random() etc.
-->String is another object having access to members like replace().match() etc
Javascript has many inbuilt methods which can be accessed by objects.
var r="rtye";
give r.length you will get its length.
Pattern matching:
RegExp is the object used for this purpose.This is used to match patterns for a specific purpose.
Syntax is
var patt=new RegExp(pattern,modifiers);
or
var patt=/pattern/modifiers;
Modifiers can be "g" or "i".."i" states that it checks "case Insensitive"
and "g" checks for the complete global scope.
eg)
var str="uiuiyUIt"
var patt1=/ui/ig; returns ui,ui,UI
or
var patt1=/ui/i; return ui,ui
Though var is generally used you can make use of
Number
String
Boolean
Undefined
Null
All the above are the primitive data types.When they are passed between functions they pass by value.
Other types are pass by "Arrays" and "Objects".They are passed by "pass by reference".
- Sourcebits University
Cloud Computing
www.sourcebits.com
-->It is a scripting language for the web.
-->It is used to handle events on the client side.
-->Is used to obtain browser information.
-->Uses AJAX fro retrieving information from the server without page reload.
-->Enables Animation and Timers Creation and setting.
Javascript includes three categories
-->Core
-->Server Side
-->DOM objects..
You start with javascript core and all other 2 will cover it up..
The HTML <script> tag is used to include a script into the html page and id is used to uniquely identify the elements.
<script type="text/javascript" src="js1.js">
You can either have the js file in the body or in the head or in another External file.
Variable declarations:
You need not specify any type in general.Just give it as
var name="blabla";
You can define functions using
function fname(arguments)
{
function bodyl;
}
Now if you want to invoke this onmouseOver give it as onMouseOver="fname()"
and the function body will be executed on that event.
Events can also be onMOuseclick,onKeyStroke,onMousedblClick etc.
An eg code to change text on mouseover:
To access a particular element in the HTml document use its unique Id.For eg if u have a paragraph with id="sin1"
then to get its value give it as
String s1=document.getElementById("sin1");
This uses the DOM structure to access the element "sin1" from the whole HTML document.
Arrays in javascript can be just given as
var e=[[[1,2,3],[5,6,7]][[5,4,6][8,7,9]];
Any dimensional array can be declared in javascript just by using "var".There are no specific types..
Date function
This is used to calculate the Date.
var d=new Date();
//gives the current date..
You can obtain the current date in millisec by using .getTime function.
You can get the current time in milliseconds using ".getmilliseconds" of the Date object.There are numerous other objects which the date's object can access.
LOOPS:
The for loop ,while loop and the "if" construct can be used as in the normal programming language."For" can also be used as below to traverse through an array..
for(x in array_name)
{
alert(array_name[x]);
}
Inbuilt Objects:
-->Math is and object which can access members like pi,random() etc.
-->String is another object having access to members like replace().match() etc
Javascript has many inbuilt methods which can be accessed by objects.
var r="rtye";
give r.length you will get its length.
Pattern matching:
RegExp is the object used for this purpose.This is used to match patterns for a specific purpose.
Syntax is
var patt=new RegExp(pattern,modifiers);
or
var patt=/pattern/modifiers;
Modifiers can be "g" or "i".."i" states that it checks "case Insensitive"
and "g" checks for the complete global scope.
eg)
var str="uiuiyUIt"
var patt1=/ui/ig; returns ui,ui,UI
or
var patt1=/ui/i; return ui,ui
Though var is generally used you can make use of
Number
String
Boolean
Undefined
Null
All the above are the primitive data types.When they are passed between functions they pass by value.
Other types are pass by "Arrays" and "Objects".They are passed by "pass by reference".
- Sourcebits University
Cloud Computing
www.sourcebits.com




No comments:
Post a Comment