Click here to Skip to main content
15,667,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I set default text for textbox during page load and clear them when focused on? I have the Text property set to "0" but it will not clear when focus is set and I would like to keep the default value if there is nothing to input into the textbox.

1 solution

try this..

<html xmlns="">
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            var txtbox = $('#<%= txtBoxControl.ClientID %>');
            var defaultText = txtbox.val();

            txtbox.focus(function () {
                if (txtbox.val() == defaultText)

            txtbox.blur(function () {
                if (txtbox.val().length == 0)


    <form id="form1"  runat="server">
    <asp:TextBox ID="txtBoxControl" runat="server" Text="some default value">
Share this answer
Computer Wiz99 6-Jan-14 22:51pm    
Thanks Karthik Bangalore. I will test it.
Karthik_Mahalingam 6-Jan-14 22:52pm    
welcome dude :)
sure you can test.
Add jquery reference to 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