Behaviors

Clear a form field on click with JS & Behaviors in Drupal 7

A common web design feature is to move the label for a form field into the field value, then clear the field once it gains focus. There are many ways to implement this functionality, but this is the Drupal 7 theming method.

These steps assume your theme contains no custom Javascript. They describe how to add the word Search to the regular Drupal search block text field.

  1. Open your template.php file.
  2. We will use hook_form_alter() to change the value of the search field:
Subscribe to Behaviors