Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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



Please vote and Accept Answer if it Helped.
 
Share this answer
 
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.
    }
}
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900