Change Text Field Colors

This function will change the colors of a form text box field by changing the style. The sample code in this example will change the background color to red and text color to white of a text box field if the value is negative. Simply call this function using an OnChange event and it will work fine. If the value is not negative then it sets the field to a standard white background with black text.

Do something like this in your text field properties:
OnChange=neg( this )

function neg( fld )
{
   fld.style.color = ( parseFloat(fld.value) < 0 ) ? 'white' : 'black';
   fld.style.backgroundColor = ( parseFloat(fld.value) < 0 ) ? 'red' : 'white';
}

You might also like...

Comments

Super Tal Always working hard!!

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Never trust a programmer in a suit.” - Anonymous