Since Javascript doesn't like to add on commas (wink), get rid of them and then validate the field to make sure it contains all usable positive numbers.
If a non-usable number is found, it redirects you back to the field, selects the fields contents for you and turns the field background to yellow. When it is corrected, the field background will turn back to white (onBlur). These colors are, of course, changeable.
Enjoy, -Mike
Step 1: Paste this into your JS header:
function IsInt (string)
{if(string == 0)
{
var val = parseFloat (string);
return val > -1
}
else
{
var val1 = string / 1;
var val = parseFloat(val1);
return val > -1
}
}
Step 2: Paste this into your fields onBlur event:
var f = document.forms[0];
//remove all commas in a number
newString = this.value.replace(/,/g , "" );
this.value = newString;
//Test for usable value
if( !IsInt(this.value)) {alert( "This field contains a value that is negative
or is not an integer or decimal." ) ;
this.focus() ; this.style.backgroundColor='yellow'}
if( IsInt(this.value)) {this.style.backgroundColor='white'} ;
Step 3: Paste the following into the onFocus field event:
select()
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.
This was first published in December 2001