diff --git a/maxlength.module b/maxlength.module
old mode 100644
new mode 100755
index 9d4438f..4b03525
--- a/maxlength.module
+++ b/maxlength.module
@@ -38,6 +38,7 @@ function maxlength_pre_render($element) {
   return $element;
 }
 
+
 /**
  * Implements hook_form_FORM_ID_alter().
  */
@@ -69,13 +70,14 @@ function maxlength_form_field_ui_field_edit_form_alter(&$form, &$form_state, $fo
       ),
     );
   }
+	
   // Add settings for textfield widgets
   $fields = array('text_textfield');
   if (in_array($form['#instance']['widget']['type'], $fields)) {
-    $form['instance']['widget']['settings']['maxlength_js'] = array(
-      '#type' => 'checkbox',
+     $form['instance']['widget']['settings']['maxlength_js'] = array(
+      '#type' => 'textfield',
       '#title' => 'Maxlength JS',
-      '#description' => t('Limit the maximum length of the field in characters using the "<strong>Maximum length</strong>" value set in the <strong>field settings</strong> using Javascript.'),
+      '#description' => t('The maximum length of the field in characters.'),
       '#default_value' => isset($form['#instance']['widget']['settings']['maxlength_js']) ? $form['#instance']['widget']['settings']['maxlength_js'] : NULL,
     );
   }
@@ -123,9 +125,9 @@ function _maxlength_children(&$element, $ms_elements) {
   foreach ($children as $child) {
     // Check if the field settings for maxlength_js are set and add the maxlength and the label text.
     if (isset($element[$child]['#field_name']) && isset($ms_elements[$element[$child]['#field_name']])) {
-      $element[$child]['#maxlength'] = isset($element[$child]['#maxlength']) ? $element[$child]['#maxlength'] : $ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js'];
+      $element[$child]['#maxlength'] = isset($ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js']) ?  $ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js']:$element[$child]['#maxlength'];
       $element[$child]['#maxlength_js'] = TRUE;
-
+			
       $maxlength_js_label = !empty($ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js_label']) ?
         $ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js_label'] : MAXLENGTH_DEFAULT_JS_LABEL;
       $maxlength_js_label = t($maxlength_js_label);
@@ -168,7 +170,7 @@ function maxlength_process_element($element, &$form_state) {
  */
 function maxlength_validate_input(&$element, &$form_state) {
   // Verify that the value is not longer than #maxlength characters.
-  if (isset($element['#attributes']['maxlength'])) {
+  if (isset($element['#attributes']['maxlength']) && isset($element['#value'])) {
     // Compute the length of the text, without counting the tags, and consider
     // the "enter" characters as only one character.
     $value = filter_xss(str_replace(array("\r\n", '&nbsp;'), array(' ', ' '), $element['#value']), array());
@@ -185,7 +187,7 @@ function maxlength_validate_input(&$element, &$form_state) {
  */
 function maxlength_form_alter(&$form, &$form_state, $form_id) {
   // Attach maxlength to node title
-  if (strpos($form_id, '_node_form') !== FALSE && variable_get('maxlength_js_' . $form['#node']->type, FALSE)) {
+  if (isset($form['#node']) && strpos($form_id, '_node_form') !== FALSE && variable_get('maxlength_js_' . $form['#node']->type, FALSE)) {
     if (!module_exists('title') || title_field_replacement_enabled('node', $form['#node']->type, 'title') !== TRUE) {
       $form['title']['#maxlength_js'] = TRUE;
       $form['title']['#maxlength'] = intval(variable_get('maxlength_js_' . $form['#node']->type, ''));
@@ -234,4 +236,4 @@ function maxlength_node_title_validate($element, &$form_state, $form) {
    if (!empty($element['#value']) && is_numeric($element['#value']) && $element['#value'] > 255) {
      form_error($element, t('Note titles can be maximum 255 characters long.'));
    }   
-}
\ No newline at end of file
+}
-- 
1.7.9.5

