diff --git a/jquery_colorpicker.module b/jquery_colorpicker.module
index c0bcaf4..3d10b09 100644
@@ -71,6 +71,8 @@ function theme_jquery_colorpicker($variables)
 {
 	$element = $variables['element'];
 	
+	$element['#id'] = isset($element['#id']) ? $element['#id'] : 'edit-' . rand(0,9999);
+	
 	$class = array('form-colorpicker');
 	$output = '';
 
@@ -161,7 +163,7 @@ function theme_jquery_colorpicker($variables)
 	$output .= '<div class="color_picker" style="background-color:' . $default_color . '">';
 	$output .= '<span class="hash">#</span>';
 	$name = isset($element['#name']) ? $element['#name'] : $element['#id'];
+	$value = isset($element['#value']) ? check_plain($element['#value']) : '';
-	$output .= '<input type="text"'. ' maxlength="6"' .' name="'. $name .'" id="'. $element['#id'] .'"'. ' size="7"' .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
+	$output .= '<input type="text"'. ' maxlength="6"' .' name="'. $name .'" id="'. $element['#id'] .'"'. ' size="7"' .' value="'. $value .'"'. drupal_attributes($element['#attributes']) .' />';
 	$output .= '<div class="description">' . t('Enter a hexidecimal color value. Enabling javascript will replace this input with a graphical color selector.') . '</div>';
 	$output .= '</div>';
 	$output .= '</div>';

