how do change html textbox color when we left the box as blank using javascipt

Posted by Kannan1986 under JavaScript on 2/12/2010 | Views : 8292 | Status : [Member] | Replies : 3
how do change html textbox color when we left the box as blank using javascipt




Responses

Posted by: Vuyiswamb on: 2/12/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You can use onblur event

&nbsp;<input id="Text1" onblur="Text1.style.backgroundColor ='Red'" type="text" />
<br />
<br />
&nbsp;<input id="Text2" onblur="Text2.style.backgroundColor ='Red'" type="text" /><br />
<br />


but you can add this in a javascript and look for empty textbox and display teh color appropriately.

Thank you for posting at Dotnetfudna

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/12/2010 [Member] Bronze

Up
0
Down
You can have checking in javascript for the text in textbox as null or not. you can assign the style too (if it's null).

Call this funtion in onblur of the text box.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/12/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Use

function CheckText()

{
var elem = document.getElementById('<% = this.yourTextbox.ClientID %>');
if(elem)
{
if(elem.value.length == 0)
elem.style.backgroundColor = '#FE2900'; //put color code here
}
}


Now call this function during onBlur. In Page_Load add

this.yourTextbox.Attributes.Add("onblur", "javascript:CheckText();");


I hope this will help you.

www.abhisheksur.com

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response