FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Field Customizations

Clearing the Value of a Field When Clicked On or Tabbed To

(2292 views. Last Updated: 2007-08-09 1:12 PM)

In this example we will demonstrate how to clear the value of a field when the user 1st clicks the field or 1st tabs to the field. We will assume that you have already used FORMgen to specify a default value for this field.

1. We will assume that you want to apply this functionality to a PersonNameField named "first_name", however this step will work with any FORMfields field that is based on a single text box. For example: TextField, TextAreaField, StreetAddressField, etc..
Replace:
$ffForm->addField(new PersonNameField("first_name", "First Name", FORM_FIELD_REQUIRED));
with:
$ffForm->addField(new PersonNameField("first_name", "First Name", FORM_FIELD_REQUIRED));
$ffForm->formFields["first_name"]->setExtraHtml("onfocus=\"if(!firstNameCleared){this.value='';firstNameCleared=true}\"");

2. Add JavaScript to your page's "head" tag:
<script type="text/javascript">
var firstNameCleared = false;
</script>
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.