Click here to Skip to main content
14,641,343 members
Rate this:
Please Sign up or sign in to vote.
See more:
Can any one help me? How do I change the text box color with javascript when validation is false? For example, if I check for null validation then I enter nothing in the textbox, it should show the colour red in the textbox, indicating that you should enter something in the textbox.
Posted
Updated 20-Oct-10 21:20pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

//C#
TextBox1.BackColor = System.Drawing.Color.Red;
//Javascript<br />
document.getElementById("TextBox1").style.backgroundColor = "#FF0000";



Please vote and Accept Answer if it Helped.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

function btn_validate_click(events){
   if(document.getelementbyid("textbox1").text + "" = ""){
       lblValidation.Text = "Nothing has been entered.";
       document.getelementbyid("textbox1").ForeColor = "Red";
       document.getelementbyid("textbox1").BackColor = "Yellow"; // or whatever colours u want.
    }
}
   
v2
Comments
Dalek Dave 21-Oct-10 3:58am
   
Just to Code Block it!

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