Click here to Skip to main content
14,243,559 members
Rate this:
Please Sign up or sign in to vote.
See more:
Basically the title, I want the textbox to be green when above 0 and red when below 0

What I have tried:

Tried doing a if statement, apparently doing it wrong.
Posted
Updated 23-Feb-16 15:53pm
Comments
clwprogrammer 23-Feb-16 21:03pm
   
use the keyup event. be sure to convert from a string to an integer or double. then use the if statement to check wether above zero or below zero. dont forget to take into account for a null string.
m.justice10 23-Feb-16 21:05pm
   
I already have all the doubles setup, this is just a small fraction of the code. I am new to C#, what is a KeyUp event? Not familiar with it.
debashishPaul 23-Feb-16 21:55pm
   
How about when the text is pasted with mouse?
debashishPaul 23-Feb-16 21:56pm
   
It is a javascript event...
http://www.w3schools.com/jsref/event_onkeyup.asp
http://www.w3schools.com/jquery/event_keyup.asp
BillWoodruff 24-Feb-16 0:14am
   
The question is ... probably ... about C#, not JavaScript
BillWoodruff 24-Feb-16 0:18am
   
Think about using a NumericUpDownControl if this is WinForms.

You need to show more of an effort here by tagging your question, and also show you have done more than just ask for what you want.

What's stopping you from looking up the 'Key Events, and trying them out by writing handlers for them ?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Because texts in the textbox can be copied from somewhere and pasted using the mouse, I would use the following:

$("#TextBoxID").bind('input propertychange', function () {
    var textLen = this.value.length;
    
    if(textLen > 0)
        //Make it green
    else
        //Make it Red
});
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100