Tuesday, September 18, 2007

Bug On Javascript Variable

I found some unussual event, when i run my javascript,
when i use a same variable, it make loop forever,
so i decide to change it with different variable, and it run =)
this is my javascript code:
=============================================================

function NumOnlyBlurWithOnGridTxt(param1, addKey)
{
var key = document.getElementById(param1.id).value;
var newValue = "";
for (i=0;i<key.length;i++)
{
if ((key.charCodeAt(i) >=48 && key.charCodeAt(i)<=57) || (key.charCodeAt(i) == 0))
{
newValue = newValue + key.charAt(i);
}
else
{
if (isAccepted(key.charCodeAt(i),addKey))
{
newValue = newValue + key.charAt(i);
}
}
}
document.getElementById(param1.id).value = newValue;
}
// second function fixed, before i use variable "i" not "j"
function isAccepted(key,addKey)
{
if (addKey != "")
{
for (j=0;j<addKey.length;j++)
{

if (key == addKey.charCodeAt(j))
{
return true;
}

}
}
return false;
}

1 comment:

Deddy Hartanto said...

Thanks for your suggestion & idea.

Hukum Tabur Tuai

Ingatlah hukum dasar ini, dalam kehidupanmu  Barang siapa yang menanam, dia pula yang akan menuai