diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index e0a2f1e8619299de4cb6198d749d4f33613d0451..c7db39372c1ce3ea34b87d4b0932a51d2bb54133 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -801,14 +801,15 @@ class SelectionWidget extends ChoicesWidget {
         ?>
         <span style="display:inline-block">
         <input type="text" size="30" name="<?php echo $this->name; ?>"
-            value="<?php echo $name; ?>" autocomplete="off" />
+            id="<?php echo $this->name; ?>" value="<?php echo $name; ?>"
+            autocomplete="off" />
         <script type="text/javascript">
         $(function() {
-            $('input[name=<?php echo $this->name; ?>]').typeahead({
+            $('input#<?php echo $this->name; ?>').typeahead({
                 source: <?php echo JsonDataEncoder::encode($source); ?>,
                 property: 'info',
                 onselect: function(item) {
-                    $('input[name="<?php echo $this->name; ?>"]').val(item['value'])
+                    $('input#<?php echo $this->name; ?>').val(item['value'])
                 }
             });
         });
diff --git a/include/class.forms.php b/include/class.forms.php
index 6385f4190ca6d16f7b2f8834f419d4a471a66152..d9dad741fc6f29c81c3187c073a4649a41db3679 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -302,7 +302,8 @@ class FormField {
 
     function getFormName() {
         if (is_numeric($this->get('id')))
-            return '-field-id-'.$this->get('id');
+            return substr(md5(
+                session_id() . '-field-id-'.$this->get('id')), -16);
         else
             return $this->get('id');
     }