Click here to Skip to main content
15,667,492 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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.
Updated 23-Feb-16 15:53pm
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.
debashishPaul 23-Feb-16 21:55pm    
How about when the text is pasted with mouse?
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:56pm    
It is a javascript event...
BillWoodruff 24-Feb-16 0:14am    
The question is ... probably ... about C#, not JavaScript

1 solution

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
        //Make it Red
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900