Library code snippets

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';
}

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Change Text Field Colors.

Leave a comment

Sign in or Join us (it's free).

Super Tal Always working hard!!
AddThis

Related podcasts

  • jQuery in ASP.NET

    In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, Scott Koon, and Steven Harman discuss Microsoft's jQuery in ASP.NET announcement.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are you loo...

Events coming up

  • Nov 20

    Full Frontal JavaScript Conference

    Brighton, United Kingdom

    A one day JavaScript conference held in Brighton, UK whose essence is to discuss JavaScript "with nothing concealed or held back".The conference is being held at one of the world's first cinemas, which first opened in 1910.Speakers include...

We'd love to hear what you think! Submit ideas or give us feedback