Re: place-holding characters in form elements

On Thursday, May 23, 2002, 12:01:54 PM, Nick Kew wrote:
> <input name="date" value="YYYY-MM-DD" onfocus="value=''">
> shouldn't be too confusing, but can never be more than an ad-hoc usage.

However, is a user enters data and then accidently tabs or clicks away and then
focuses back on the field, the data will be cleared.

If you really feel the need for default text, then it is better to do something
along the lines of:

  <input name="date" value="YYYY-MM-DD"
  onfocus="if(!this.cleared){this.value='';this.cleared=true;}" />

This should only clear the text once.
  
You can also do this.select() onfocus, to select all the text - when the user
starts typing, that text will generally be deleted. Often users don't realize
this however, and delete the text first anyway.

-- 
Tom Gilder
http://tom.me.uk/

Received on Thursday, 23 May 2002 16:41:03 UTC