Thursday, August 14, 2008

Replace the existing string with the new string

function replaceAllString( str, from, to )
{
var idx = str.indexOf( from );


while ( idx > -1 )
{
str = str.replace( from, to );
idx = str.indexOf( from );
}
}

if you want to replace all commas (,) in a string then the above function will work in javascript

example if the textbox value 1,24,573.00 and while storing into the database if should be just like 124573.00 then you have to replace all commas, so for that the user has to write
document.getElementById("txtBoxId").value = replaceAllStrings(document.getElementById("txtBoxId").value,",","");

Hope this helps you

Kumar