diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index cdb2606ddc47106c1a0f49765e2ac1aa70593db0..7771802bc98bd051261fac91c6dc92f4d7f27a6a 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -808,14 +808,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 4250e258ce66b7dd3b29faf651ef82af1a85ddf1..356c504da90a38d2357975e5777a310c5e3d3ee1 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -309,7 +309,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');
     }