Detecting Ajax Support

check if your browser/javascript supports Ajax.
For this we can use prototype’s getTransport method.

if (Ajax.getTransport()) {
//supports ajax
}else{
alert(‘Ajax not supported’)
}

You can include this onload of your page. Make sure that before checking this , to include the prototype.js in your page

This will actually check for XML parsers in IE / FF with browser specific methods.

trim, ltrim and rtrim in javascript

Trim , Left trim (ltrim) and Right Trim (rtrim) in javascript


//Function to trim the space in the left side of the string
function ltrim ( s ){
return s.replace( /^s*/, "" );
}

//Function to trim the space in the right side of the string
function rtrim ( s ){
return s.replace( /s*$/, "" );
}

//*Function to trim the space in the  string
function trim(s) {
var temp = s;
return temp.replace(/^s+/,'').replace(/s+$/,'');

ltrim() will remove all the spaces to the left in a string rtrim() will remove all the spaces to the right in a string trim() will all the left , right and spaces inside the string Ex: var x = ” thestring”; ltrim(x) will return “thestring”; var y = “thestring “; rtrim(y) will return “thestring”; var z = ” the st ri ng “; trim(z) will return “thestring”

How to Uninstall IE7 Beta

How to Uninstall IE7 Beta. Here is a simple way to uninstall IE7 Beta. uninstalling IE7 first seemed to be a hectic task and i thought that my system would crash. But it was as simple like uninstalling a normal software. Thank God. I got the IE6 back.

1. Go to Control Panel
2. Click Add or Remove Programs
3. Click Show Updates checkbox
4. Click whatever version of IE7 you have. For example “Internet Explorer 7 Beta 2 Preview”
5. Click the Change/Remove button

Check for Duplicates in an array

This Function will check for duplicate entries in an array and return true or false

For Single Dimensional Array
Array.prototype.chkforDuplicates = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return true; } } return false; }; For Multi Dimensional Array
Array.prototype.chkforDuplicates = function (value,Idx)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i][Idx] == value) { return true; } } return false; }; ong>Note: Idx is the Value of the Column You want to check for duplicates

How to Find the Index/Position of an element in an array

This js function will find the index of an array element with the given value in an array.
for Example you are having an array like

var mnuArray = new Array(“Groups”,”Services”,”Applications”);

And want to know the index/position of and element in an array, then
you can call mnuArray.findIndex(“Services”);
This will return “1”.

This will be helpful if you are having a large size array/the elements are unknown which you have populated from an dB

Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return i; } } return ctr; };

And advanced version of this function is,
If you want to do the same in the case of multidimensional arrays
then use the following

Array.prototype.findIndexByCol = function(value,cIdx){
var ctr = "";
for (var i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i][cIdx] == value) { //alert(this[i][cIdx]+"===="+value); return i; } } return ctr; };

Functions find Left and Right position of an Object

When a layer is inside another layer, it’s style.left and style.top positions can both be ‘0’
but the layer itself can be 500 pixels away from the actual margin. These functions will return
the true offset.
// To find the left position, add this snippet to your code:

function getPositionLeft(This){
var el = This;var pL = 0;
while(el){pL+=el.offsetLeft;el=el.offsetParent;}
return pL
}

// To find the top position, add this snippet to your code:

function getPositionTop(This){
var el = This;var pT = 0;
while(el){pT+=el.offsetTop;el=el.offsetParent;}
return pT
}

Get all Indexes of Duplicate Entries in an array

Array.prototype.collectDuplicateIndices = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var dupesStr = “”;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { dupesStr += i+","; } } return (dupesStr>“”)?dupesStr:”null”;
};

This will return all the index/positions of the duplicate entries in an Array as a string seperated with commas.

For example the Returned string will be 1,77,55
Where 1,77 and 55 are the positions of the duplicate entries in the array. ( Or you can say those positions are having the duplicate entries)

Check if an element or value exists in an array or not

This function will Check if an element or value exists in an array or not.
And return true if the passed value is found in the array. Returns false if it is not found in the array.

Array.prototype.inArray = function (value,caseSensitive)
// Returns true if the passed value is found in the
// array. Returns false if it is not.
{
var i;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), if(caseSensitive){ //performs match even the string is case sensitive if (this[i].toLowerCase() == value.toLowerCase()) { return true; } }else{ if (this[i] == value) { return true; } } } return false; }; Note : If you don't want to perform case sensitive check, then set caseSensitve=true and call the function.