Form Textboxes

Discussion in 'HTML & Website Design' started by Weirfire, Oct 18, 2005.

  1. #1
    I was wondering if anyone knew how to do those textboxes where it says something like "enter text here" and as soon as you click on the textbox this text disappears?
     
    Weirfire, Oct 18, 2005 IP
    mcfox likes this.
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try
    <input type="text" value="Enter your text" onfocus="value=''" name="textfield" size="20">
    HTML:
     
    dave487, Oct 18, 2005 IP
    Weirfire likes this.
  3. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Will that be the same for <textarea> ?

    yes it is :)
     
    Weirfire, Oct 18, 2005 IP
  4. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Never tried it but would assume so.

    Its the
    value="Text" onfocus="value=''"
    HTML:
    that makes it work so as long as you add that it should be fine.
     
    dave487, Oct 18, 2005 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Thanks Dave, that's great :)
     
    Weirfire, Oct 18, 2005 IP
  6. Arnica

    Arnica Peon

    Messages:
    320
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi Weirfire

    The onfocus event fires again if the user switches input fields and returns to amend their input (rather annoying for the user if they only wanted to correct a typo in a long input field). You need to turn off the onfocus event after the first firing. This would do the trick.

     
    onfocus="this.value='';this.onfocus='';"
    
    Code (markup):
    Cheers

    Mick
     
    Arnica, Oct 18, 2005 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    Thanks Arnica :)

    These little tricks are great for usability :)
     
    Weirfire, Oct 18, 2005 IP
  8. durango

    durango Guest

    Messages:
    83
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You could also do this if they clear out the textfield after putting stuff into it:

    
    <input type="text" name="textfield" onfocus="if (this.value=='Enter text') { this.value = '';}" onblur="if (this.value=='') { this.value = 'Enter text'; }" value="Enter text">
    
    Code (markup):
     
    durango, Oct 18, 2005 IP
  9. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #9
    Thanks durango.

    Seems everyone knows these tricks already except me. :eek:
     
    Weirfire, Oct 19, 2005 IP
  10. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #10
    If you're looking at quite a complicated HTML form, I would also encourage you to use Javascript form validation - much less annoying for the user in my opinion. There are plenty of prewritten examples around. I can't find the original I used but you can find some if you Google it.

    You would also obviously have to implement server side validation for browsers that don't support Javascript.

    - Jamie
     
    JamieC, Oct 19, 2005 IP