<asp:TextBox ID="TxtBOX"
runat="server"
CssClass="text"
Height="32px"
Width="360px"
TextMode=MultiLine
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible"
onclick="if(this.value='<%=_data.Obsprevia.ToString()%>'){this.value=''}"
onblur="if(this.value=''){this.value='<%=TxtObservaciones.Text.ToString()%>'}">
</asp:TextBox>
That’s my code.
Default TxtBOX.Text comes from code behind (_data_obsprevia). What I want to achieve is, a clean up of that default text once the user clicks on the textbox. And if the txbox lose focus while the user didn’t write anything, get back that default text.
I can’t achieve that, and if the user DID write something, and lose-gain focus again, the textbox gets empty again.
Thanks.
EDIT
Fixed the == inside the IFs, Now it looks like this
<asp:TextBox ID="TxtBOX"
runat="server"
CssClass="text"
Height="32px"
Width="360px"
TextMode=MultiLine
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible"
onclick="if(this.value=='<%=_data.Obsprevia.ToString()%>'){this.value=''}"
onblur="if(this.value==''){this.value='<%=TxtObservaciones.Text.ToString()%>'}">
</asp:TextBox>
But when I first click on it, it’s not cleaning the deafult data. And if I erase it, and go losing focus it shows <%=TxtObservaciones.Text.ToString()%>
Not the value held inside of it.
Try this, a build onto insertusernamehere’s suggestion..
This gets what is set in the textbox from javascript, in case it is changed in the browser.
You also might need to break the code out into functions
and