Archive for September, 2006

Debugging in javascript without alert dialog

To debug javascript code we use alert() whereever needed and it irritates you while alerts values inside a loop and other places where more alerts are being shown and you have to press the ok button to pass / proceed on.
here is a simple way to get rid of the alerts dialogs and get the values outputed into another debug window

Read the rest of this entry »

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”

Feedback Form