www.webdeveloper.com
Results 1 to 7 of 7

Thread: OnFocus Clear text

  1. #1
    Join Date
    Mar 2007
    Posts
    3

    OnFocus Clear text

    I am writing a note taking system in PHP and admittedly do not know Javascript. The first page features a textbox with the message "Enter text here" initially. Is there a way to have the text be cleared when the user clicks of focuses of the textbox?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    You'll get complaints when the user fills out a form and erases his own input.

    Better to either select the field onfocus, which highlights the default text and replaces it when the user starts typing, or begin with the box empty.

  3. #3
    Join Date
    Mar 2007
    Posts
    3
    how can that be done?

  4. #4
    Join Date
    Feb 2006
    Posts
    2,927
    element.onfocus=function(){element.select()}

  5. #5
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    you could do something like this
    PHP Code:
    <input type="text" name="field"  value="Value" onfocus="if(this.value=='Value')this.value=''" /> 
    Where it looks to see if the value is the original value, if it is, it will reset it, if it is not or is something the user has entered it will not reset it.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    <input type="text" name="field" value="no_matters" onfocus="this.value==this.defaultValue?this.value='':null">
    Last edited by Kor; 03-29-2007 at 04:03 PM.

  7. #7
    Join Date
    Mar 2007
    Posts
    3
    thank you, work just how i expected it to.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles