WHAT'S NEW?
Loading...
Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts


Browser


It is important to understand the differences between different browsers in order to handle each in the way it is expected. So it is important to know which browser your web page is running in.

To get information about the browser your webpage is currently running in, use the built-in navigator object.


IMAGE MAP

You can use JavaScript to create client-side image map. Client-side image maps are enabled by the usemap attribute for the <img /> tag and defined by special <map> and <area> extension tags.

The image that is going to form the map is inserted into the page using the <img /> element as normal, except that it carries an extra attribute called usemap. The value of the usemap attribute is the value of the name attribute on the <map> element, which you are about to meet, preceded by a pound or hash sign.

The <map> element actually creates the map for the image and usually follows directly after the <img /> element. It acts as a container for the <area /> elements that actually define the clickable hotspots. The <map> element carries only one attribute, the name attribute, which is the name that identifies the map. This is how the <img /> element knows which <map> element to use.

The <area> element specifies the shape and the coordinates that define the boundaries of each clickable hotspot.

The following code combines imagemaps and JavaScript to produce a message in a text box when the mouse is moved over different parts of an image.

Every now and then, developers commit mistakes while coding. A mistake in a program or a script is referred to as a bug.

The process of finding and fixing bugs is called debugging and is a normal part of the development process. This section covers tools and techniques that can help you with debugging tasks.

You can use JavaScript to create a complex animation having, but not limited to, the following elements:

·         Fireworks

·         Fade Effect

·         Roll-in or Roll-out

·         Page-in or Page-out

·         Object movements

FORM VALIDATION

Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button. If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information. This was really a lengthy process which used to put a lot of burden on the server.


ERRORS AND EXCEPTIONS


There are three types of errors in programming: (a) Syntax Errors, (b) Runtime Errors, and (c) Logical Errors.

reverse ()

JavaScript array reverse() method reverses the element of an array. The first array element becomes the last and the last becomes the first.

Syntax

Its syntax is as follows:

array.reverse();

Return Value

Returns the reversed single value of the array.

lastIndexOf ()

Javascript array lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

Syntax

Its syntax is as follows:

array.join(separator);

Array Methods

Here is a list of the methods of the Array object along with their description.


The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

fontsize ()

This method causes a string to be displayed in the specified size as if it were in a <font size="size"> tag.

Syntax

Its syntax is as follows:

string.fontsize( size )

Attribute Details

size: An integer between 1 and 7, a string representing a signed integer between 1 and 7.

Return Value

Returns the string with <font size="size"> tag.

String HTML Wrappers

Here is a list of the methods that return a copy of the string wrapped inside an appropriate HTML tag.

toLowerCase ()

This method returns the calling string value converted to lowercase.

Syntax

Its syntax is as follows:

string.toLowerCase( )

Return Value

Returns the calling string value converted to lowercase.

split ()

This method splits a String object into an array of strings by separating the string into substrings.

Syntax

Its syntax is as follows:

string.split([separator][, limit]);

localeCompare ()

This method returns a number indicating whether a reference string comes before or after or is the same as the given string in sorted order.

Syntax

The syntax of localeCompare() method is:

string.localeCompare( param )

The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.

As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.

The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.

Syntax

Use the following syntax to create a boolean object.


var val = new Boolean(value);

NEGATIVE_INFINITY

This is a special numeric value representing a value less than Number.MIN_VALUE. This value is represented as "-Infinity". It resembles an infinity in its mathematical behavior. For example, anything multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY, and anything divided by NEGATIVE_INFINITY is zero.

Because NEGATIVE_INFINITY is a constant, it is a read-only property of Number.

The Number object represents numerical date, either integers or floating-point numbers. In general, you do not need to worry about Number objects because the browser automatically converts number literals to instances of the number class.

Syntax

The syntax for creating a number object is as follows:


var val = new Number(number);

In the place of number, if you provide any non-number argument, then the argument cannot be converted into a number, it returns NaN (Not-a-Number).


JavaScript is an Object Oriented Programming (OOP) language. A programming language can be called object-oriented if it provides four basic capabilities to developers:

·         Encapsulation: the capability to store related information, whether data or methods, together in an object.

·         Aggregation: the capability to store one object inside another object.

·         Inheritance: the capability of a class to rely upon another class (or number of classes) for some of its properties and methods.

·         Polymorphism: the capability to write one function or method that works in a variety of different ways.

Objects are composed of attributes. If an attribute contains a function, it is considered to be a method of the object, otherwise the attribute is considered a property.