Input form question

Discussion in 'HTML & Website Design' started by Camay123, Mar 26, 2008.

  1. #1
    Is it possible to have text in the input box of a form, and when the user click in the text box, the text disapear and he can type whatever in need to write ?
     
    Camay123, Mar 26, 2008 IP
  2. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Uhh, I think this should do the trick:

    HEAD section:

    <script language="Javascript">
     <!--
    
     function doClear(theText) 
    {
         if (theText.value == theText.defaultValue)
     {
             theText.value = ""
         }
     }
     //-->
     </script>
    Code (markup):
    BODY section:

    <form>
    <input type="text" size=15 value="Value here" onFocus="doClear(this)">
    </form>
    Code (markup):
     
    Dondon2d, Mar 26, 2008 IP
    Camay123 likes this.
  3. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You don't even need the javascript to control it, use this inside your <form> tags:

    <input type="text" name="Search" size="25" value="Default Text" onfocus= "if (this.value=='Default Text') this.value='';" onblur="if (this.value=='') this.value='Default Text';">
    
    Code (markup):
    I know it works - I use the same piece of code on all my sites :)
     
    Spider-Man, Mar 26, 2008 IP
    Camay123 likes this.
  4. Camay123

    Camay123 Well-Known Member

    Messages:
    3,423
    Likes Received:
    86
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Yup. This as done the job. A rep point given to both of you.
     
    Camay123, Mar 26, 2008 IP
  5. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Epp, yeah thanks. I just made the function so you don't have to write over and over again assuming you have lots of text boxes/areas on your page.

    Thanks for the rep.
     
    Dondon2d, Mar 26, 2008 IP
  6. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Glad you got it working:)

    Thanks for the rep
     
    Spider-Man, Mar 26, 2008 IP