--- maxlength.js	Fri Jan 16 05:21:36 1970
+++ maxlength.js	Fri Jan 16 05:21:36 1970
@@ -1,55 +1,54 @@
-/* $Id: maxlength.js,v 1.1.6.6.2.13 2010/06/27 07:44:50 dereine Exp $ */
-
-Drupal.maxLength_limit = function (field, maxlength) {
-
-  // calculate the remaining count of chars
-  var limit = maxlength.limit;
-  var length = field.val().length;
-  var remainingCount = limit - length;
-
-  // if there is not remaining char, we clear additional content
-  if (remainingCount < 0) {
-    field.val(field.val().substr(0, limit));
-    remainingCnt = 0;
-  }
-
-  // Update the remaing chars text.
-  maxlength.span_remaining_count.html(remainingCount.toString());
-  // And the current count.
-  if (maxlength.show_count) {
-    maxlength.span_count.html(length.toString());
-  }
-}
-
-Drupal.behaviors.maxlength = function (context) {
-  // Get all the settings, and save the limits in the fields.
-  var maxlength = {};
-  var element = {};
-  var limit = 50;
-  for (var id in Drupal.settings.maxlength) {
-    limit = Drupal.settings.maxlength[id];
-    element = $("#"+ id);
-    maxlength = $('#maxlength-' + element.attr('id').substr(5));
-
-    maxlength.limit = limit;
-    maxlength.show_count = false;
-    maxlength.span_remaining_count = maxlength.find('span.maxlength-counter-remaining');
-    maxlength.find('span.maxlength-count', function() {
-      maxlength.show_count = true;
-      maxlength.span_count = maxlength.find('span.maxlength-count');
-    });
-
-    // Update the count at the page load.
-    Drupal.maxLength_limit(element, maxlength);
-
-    element.load(function() {
-      Drupal.maxLength_limit(element, maxlength);
-    });
-    element.keyup(function() {
-      Drupal.maxLength_limit(element, maxlength);
-    });
-    element.change(function() {
-      Drupal.maxLength_limit(element, maxlength);
-    });
-  }
-}
+/* $Id: maxlength.js,v 1.1.6.6.2.13 2010/06/27 07:44:50 dereine Exp $ */
+
+Drupal.maxLength_limit = function (field) {
+
+  // Build maxlength values and settings
+  var id = $(field).attr('id');
+  var limit = Drupal.settings.maxlength[id];
+  var maxlength = $('#maxlength-' + id.substr(5));
+  maxlength.show_count = false;
+  maxlength.span_remaining_count = maxlength.find('span.maxlength-counter-remaining');
+  maxlength.find('span.maxlength-count', function() {
+    maxlength.show_count = true;
+    maxlength.span_count = maxlength.find('span.maxlength-count');
+  });
+
+  // calculate the remaining count of chars  
+  var length = $(field).val().length;
+  var remainingCount = limit - length;  
+
+  // if there is not remaining char, we clear additional content
+  if (remainingCount < 0) {
+    $(field).val($(field).val().substr(0, limit));    
+  }  
+
+  // Update the remaing chars text.
+  maxlength.span_remaining_count.html(remainingCount.toString());
+  // And the current count.
+  if (maxlength.show_count) {
+    maxlength.span_count.html(length.toString());
+  }  
+}
+
+Drupal.behaviors.maxlength = function (context) {
+  // Get all the settings, and save the limits in the fields.
+  var element = {};
+  for (var id in Drupal.settings.maxlength) {
+  
+    element = $("#"+ id);    
+        
+    // Update the count at the page load.
+    Drupal.maxLength_limit(element);
+
+    // Setup events
+    element.load(function() {
+      Drupal.maxLength_limit(this);
+    });
+    element.keyup(function() {
+      Drupal.maxLength_limit(this);
+    });
+    element.change(function() {
+      Drupal.maxLength_limit(this);
+    });
+  }
+}
--- maxlength.module	Fri Jan 16 05:21:36 1970
+++ maxlength.module	Fri Jan 16 05:21:36 1970
@@ -69,12 +69,12 @@
     $list = array_keys(content_fields(NULL, $type));
 
     // Update CCK fields as needed
     foreach ($list as $field) {
       if (is_array($form[$field])) {
-        foreach (element_children($form[$field]) as $key) {
-          if ($form[$field][$key]['#type'] == 'text_textarea') {
+        foreach (element_children($form[$field]) as $key) {          
+          if ($form[$field][$key]['#type'] == 'text_textarea' || $form[$field][$key]['#type'] == 'text_textfield') {
             _maxlength_format_element($form[$field][$key], $form[$field][$key]['#default_value']['value'], $field, str_replace('_', '-', $field) .'-'. $key .'-value', $type);
           }
         }
       }
     }
@@ -176,11 +176,11 @@
  *   Could this all be done without drupal_add_js and just theming of the form element.
  *   Can we use a theme function to let alter the placement of the maxlength text.
  */
 function _maxlength_format_element(&$element, $value, $field, $id, $type = '') {
   $values = _maxlength_get_values($field, $type);
-
+  
   if ($values !== FALSE AND isset($values['limit']) AND $values['limit'] AND $values['use_js']) {
     $path = drupal_get_path('module', 'maxlength');
     drupal_add_js($path .'/maxlength.js');
 
     $remaining = $values['limit'] - drupal_strlen($value);
