You are viewing limited content. For full access, please sign in.

Question

Question

Set drop-down field default when populating with database query.

asked on December 12, 2014

We have a Forms drop-down populated by a database query.  When a user selects a value from the drop-down, numerous other forms fields are populated by the lookup match.  One user suggested that we default the value of the drop-down to the most commonly selected value.  I wasn't sure we could do this with a database query populating the drop-down, but figured out a way using jQuery:

  function setSelectDefault(cssSelector, defaultValue) {
    var select = $(cssSelector + ' select');
    select.append($('<option>', { value: defaultValue }).text(defaultValue));
    select.val(defaultValue);
    select.change();
  }
  ...
  ...
  ...
  setSelectDefault('.dropDownClass', 'Foobar'); 

The above code looks for the drop-down identified by the class .dropDownClass, adds an option named Foobar and selects it, and then fires the drop-down change event to do the lookup match.  Seems to work great!  Once the json fires that populates the drop-down with database query results, the appropriate value remains selected.

 

Any issues with this?

0 0

Answer

SELECTED ANSWER
replied on December 14, 2014

Forms itself support configure default value for a dropdown field and when the lookup result contains the default value, it can use that value to trigger other lookup rules. so you can just add the option "Foobar" to the choice of the dropdown and click the number before it to set it as default value as following:

2 0
replied on May 15, 2015

Hello, can you confirm if this functionality is still present in version 9.2.1.1069?  Thanks!

0 0
replied on February 23, 2016

its still there

0 0
replied on September 4, 2017

This works well. However, how can I have the default value as blank? I have tried the space and no values.

Thanks

0 0

Replies

replied on December 15, 2014

Thank you, that worked well!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.