Javascript field modifications in Drupal

Here is a quick little code snippet that can be added to a hook_form_alter() function in Drupal. It adds a little Javascript to automatically set a field value to upper-case.

// Modify this array to show the actual field names in your form.
    $uppercase_fields = array(
      'field_textfield1',
      'field_textfield2',
      'field_textfield3',
      );
    foreach($uppercase_fields as $delta => $item) {
      $filter .= "input:text[@name^=$item],";
    }
    drupal_add_js("
      $(document).ready(function () {
        $('$filter').change(function() {
          $(this).val($(this).val().toUpperCase());
        });
      });", 'inline');

This is tested to work on Drupal 6.