Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am working on a webApplication.In that I have taken a textbox in which text property have entered 0.00.So if I'll click on it the textbox should be blank and if I'll leave the textbox
it has again the same value as 0.00.

So wanted to know this...if anybody is there can help me then please help me as soon as possible.


Thanks,
Posted

If you are working on webapplication (I assume its .net), then you can use javascript function as below


XML
<script type="text/javascript">
       function blanktextbox() {
           var textbx = document.getElementById('<%=TextBox1.ClientID%>');
           if (textbx.value == '0.00')
               textbx.value = '';
       }

       function filltextbox() {
           var textbx = document.getElementById('<%=TextBox1.ClientID%>');
           if (textbx.value == '')
               textbx.value = '0.00';
       }
   </script>


And in HTML your textbox will be

ASP.NET
<asp:textbox id="TextBox1" runat="server" onfocus="blanktextbox();" onblur="filltextbox();" xmlns:asp="#unknown"></asp:textbox>


and you are done :)
 
Share this answer
 
Comments
Ankur\m/ 17-Apr-13 4:52am    
Though your solution to the question literally is right, I think this really isn't what OP is looking for.
What's the use of a textbox which cannot be used to enter any value. Yes, your code will always make the value 0.00 on blur, no matter what I enter.
PrashantSonewane 17-Apr-13 5:58am    
revisite my code again. It will only make 0.00 if the value in textbox is blank. And thats what the request was.
Ankur\m/ 17-Apr-13 6:04am    
Okay I missed that part. You got my 5 then! :)
PrashantSonewane 17-Apr-13 6:05am    
thanks :)
Shivani Dash 17-Apr-13 5:23am    
Thank you..Prasant.It worked. :)
You care looking for textbox watermarking[^].
There are may ways to do it - using JavaScript/jQuery, there are custom controls for the same.
The link will help you check out various options. See what best suits your need.

Hope that helps!
 
Share this answer
 
Comments
Shivani Dash 17-Apr-13 5:28am    
Thanks Ankur for replying... :)

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