|
function NumericInputClass()
{
function NumericInputKillExtraDigits(Val, Type, DecimalSeparator)
{
if(Type == 0)
return(Val);
if(Type == 1)
return(Val);
var DotPos = Val.indexOf(DecimalSeparator);
if(DotPos == -1)
return(Val+DecimalSeparator+"00");
Val += "00";
return(Val.slice(0, DotPos+3));
}
function FixData(This, Type, DecimalSeparator)
{
var Val = This.value;
var NewVal = "";
var GotDot = false;
for(var i=0; i<Val.length; i++)
{
var c=Val.charAt(i);
if(c == "-" && i == 0)
{
NewVal += c;
continue;
}
// window.alert("new: '"+NewVal+"' c: '"+c+"'");
if(c == DecimalSeparator)
{
if(Type == 0)
{
This.value = NewVal;
return;
}
if(GotDot == true)
{
This.value = NumericInputKillExtraDigits(NewVal, Type, DecimalSeparator);
return;
}
NewVal += c;
GotDot = true;
continue;
}
if(c >= '0' && c <= '9')
NewVal += c;
}
This.value = NumericInputKillExtraDigits(NewVal, Type, DecimalSeparator);
}
this.FixData = FixData;
function Check(Type, DecimalSeparator)
{
var Obj = event.srcElement;
var Val = Obj.value;
var Key = event.keyCode;
var KeyAscii = String.fromCharCode(Key);
if(KeyAscii == "-")
{
if(Obj.value != "")
{
event.returnValue = false;
return;
}
return;
}
switch(Type)
{
case 0: // integer
if(KeyAscii < '0' || KeyAscii > '9')
{
event.returnValue = false;
return;
}
return;
case 1: // Float
case 2: // Currency
var DotPos = Val.indexOf(DecimalSeparator);
if(KeyAscii == DecimalSeparator)
{
if( DotPos >= 0)
{
event.returnValue = false;
return;
}
return;
}
if(KeyAscii < '0' || KeyAscii > '9')
{
event.returnValue = false;
return;
}
return;
}
}
this.Check = Check;
}
var NumericInput = new NumericInputClass();
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.