tri_inn Level: Regular User Registered: 26-08-2002 Posts: 395
|
Need crossbrowser javascript for numeric textbox ?
i have developed a numeric textbox web server control. it generates javascript when form load but
my javascript only works in IE browser. so please give me the same javascript which will work in
IE & Netscape.i just can not understand why my avascript function called DoCheck_NumBox1(event,tBox)
is not going to be called when i am working with netscape browser6/7.please tell me where is the problem
lies in my whole code.
here i am giving my javascript with html code which is generated by my control
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>TestCtrl</title>
<script language="JavaScript">
function DoCheck_NumBox1(event,tBox)
{
var negative;
var Decimal = 46;
var DeciPlaces =2;
var AllowNegative =true;
var myString = new String(event.srcElement.value);
var pntPos = myString.indexOf(String.fromCharCode(Decimal));
var keyChar = window.event.keyCode;
//alert(keyChar);
if(keyChar == 45)
{
if (AllowNegative == true)
{
negative=myString.indexOf('-');
if (negative == -1)
{
if (myString.length <= 0)
{
return true;
}
else
{
if (negative == -1)
{
var hVal=tBox.value;
tBox.value="-"+hVal;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
}
if (keyChar == Decimal)
{
if (pntPos != -1)
{
return false;
}
else
{
if(DeciPlaces <=0)
{
return false;
}
else
{
return true;
}
}
}
if ((keyChar < 48) || (keyChar > 57))
{
return false;
}
else
{
if (pntPos != -1)
{
if ((myString.length - (pntPos + 1)) >= DeciPlaces)
{
return false;
}
else
{
return true;
}
}
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="TestCtrl.aspx" id="Form1">
<input type="text" id="NumBox1" onkeypress="javascript:return DoCheck_NumBox1(event,this);" style="Z-INDEX: 101; LEFT: 351px; POSITION: absolute; TOP: 211px" />
</form>
</body>
</HTML>
|