How to display default text in a textbox using vb.net?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prathap
    New Member
    • Nov 2011
    • 37

    How to display default text in a textbox using vb.net?

    I have a textbox,it should display something like "please enter your name" by default.

    The default text must disappear when i click on that textbox.

    Could someone please help..
  • Sivaranjani
    New Member
    • Dec 2011
    • 16

    #2
    Give the default value For Textbox using Value Attribute in input control.


    <input id="id" type="text" value="please enter your name" onclick="Change ()" />


    Call the Javascript Function When You Click on the Textbox.

    <script type="text/javascript" language="javas cript">
    function Change() {
    document.getEle mentById("id"). value = "";
    }
    </script>

    Comment

    • pod
      Contributor
      • Sep 2007
      • 298

      #3
      it's a good suggestion, and you might want to add this to the script, in case the user clicks back into it by mistake

      Code:
      if (document.getElementById("id").value == "please enter your name"){
      		document.getElementById("id").value = "";
      	}

      Comment

      • Prathap
        New Member
        • Nov 2011
        • 37

        #4
        Thanks pod,thanks Sivaranjani
        I am using vb.net,I have found the answer.
        Thanks for your concern.

        Comment

        • sirasingh
          New Member
          • Nov 2011
          • 2

          #5
          You can also do by changing the text property of textbox .
          for example
          textbox1.text= "please enter your name"
          Last edited by Niheel; Dec 20 '11, 03:29 PM.

          Comment

          Working...