B2B Marketing Insights by Ironpaper

Clear form field with mouse click using simple Javascript (focus)

Written by Ironpaper | May 18, 2011

Making a user's experience enjoyable and hassle-free is a vital part of web design and development. In many website projects, you may need to have an HTML form with values pre-filled to describe the type of field the user is accessing.  This is one of the simplest ways to execute this approach. It uses a simple  event called onFocus to remove the text within "value".


<input type="text" name="myField" size=16 value="Click to remove text" onFocus="javascript:this.value=''" />
<input type="submit" />