Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all

i am working on watermark text boxes
i am using javascript to do that

here below is the complete code

XML
<script language="javascript" type="text/javascript">
         function Focus(objname, waterMarkText) {
             obj = document.getElementById(objname);
             if (obj.value == waterMarkText) {
                 obj.value = "";
                 obj.className = "NormalTextBox";
                 if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                     obj.style.color = "black";
                 }
             }
         }
         function Blur(objname, waterMarkText) {
             obj = document.getElementById(objname);
             if (obj.value == "") {
                 obj.value = waterMarkText;
                 if (objname != "txtPwd") {
                     obj.className = "WaterMarkedTextBox";
                 }
                 else {
                     obj.className = "WaterMarkedTextBoxPSW";
                 }
             }
             else {
                 obj.className = "NormalTextBox";
             }

             if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                 obj.style.color = "gray";
             }
         }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

  <table>
        <tr>
            <td>
                User Id
            </td>
            <td>
                <asp:TextBox ID="txtUserId" runat="server"
        onfocus="Focus(this.id,'User ID')"
                    onblur="Blur(this.id,'User ID')"
            Width="126px" CssClass="WaterMarkedTextBox">User ID</asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Password
            </td>
            <td>
                <asp:TextBox ID="txtPwd" TextMode="Password"
        runat="server" onfocus="Focus(this.id,'')"
                    onblur="Blur(this.id,'')" Width="126px"
            CssClass="WaterMarkedTextBoxPSW" />
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Focus(this.id,'User ID')" />
            </td>
        </tr>
    </table>



now problem is that suppose i am not entering username
so on submit click txtuserid goes empty at server side

but it contain value that assigned in weatermark
i hav to clear that value

plz suggest sumthing
Posted

here below is the solution

C#
function ControlTypes() {
               for (i = 0; i < document.forms[0].length; i++) {
                   doc = document.forms[0].elements[i];
                   var type = doc.type;

                   if (type == "text") {
                       if (doc.style.color == "Aqua") {
                           var asa = doc.value;
                           doc.value = '';
                       }
                       else
                       { }

                   }
               }
           }




jsut clear the textboxes on click if there color is same(define in css)
 
Share this answer
 
Use Ajax control.Inbuilt control is there for watermark text
 
Share this answer
 
Comments
sharmarun 22-Sep-11 6:41am    
i dont want to use ajax
its project requirement
plz suggest another option

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