I've been stuck on this issue for over a day now and can't seem to figure out why my code isn't working. I'm creating a web page in ASP.NET and trying to implement a text box with gray placeholder text that changes to black when clicked. Here's the code I have so far:
<asp:TextBox ID="addEditTextBox1" runat="server" onselect="if(style.color=='#999999'){style.color='Black'; this.value='';}" onclick="if(style.color=='#999999'){style.color='Black';this.value='';}" ForeColor="#999999" Width="250px">Revision #</asp:TextBox>
I've tried different variations of the "if" statement triggers such as
if(style.color.value=='#999999'){...}
and
if(ForeColor=='#999999'){...}
and
if(ForeColor.value=='#999999'){...}
but none seem to work. I know the onclick and onselect statements are functioning as expected because if I use "=" instead of "==" they trigger every time. However, that defeats the purpose of an "if" statement. I'm new to ASP.NET and JavaScript, so I might be missing something obvious. Additional information that might be useful:
- Using Visual Studio Professional 2012
This is located near the top of the page's source code:
<html xmlns="http://www.w3.org/1999/xhtml">
Target Framework: .NET Framework 4.5.
If you need more details, feel free to ask. Thank you!