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

Question

Question

Fill drop down list from columns in a table on a previous form

asked on March 29, 2021

Hello, Can you populate a drop down list with results from a column in a table? I have a form where they need to fill in table with vendor names and then the form will go to a manager for approval, what I would like is then on the manager's form for them to pick a vendor from a drop list based on the vendors listed in table.

0 0

Answer

SELECTED ANSWER
replied on March 29, 2021

Here's one way to do it.  This assumes your table has a Class Name of myTable, the field in the table with the vendor names has Class Name of myTableField, and the drop-down field has a Class Name of myDropDown: 

$(document).ready(function() {
  
  //When the form is loaded, call the function to populate the existing table data into the dropdown
  loadTableDataToDropDown();
  
  //When the table is changed, call the function to populate the table data into the dropdown
  $('.myTable').change(loadTableDataToDropDown);
  
  //This function is called to load all the values from the table into the drop-down
  //the options in the drop-down will be cleared, and the new options from the table
  //will be loaded.
  function loadTableDataToDropDown()
  {
    $('.myDropDown select').find('option').remove();
    $('.myTableField input').each(function() {
      if ($(this).val() != '')
      {
        $('.myDropDown select').append(new Option($(this).val(), $(this).val(), false, false));
      }
    });
  }
  
});

 

0 0
replied on April 25, 2022

Hello,

This is really helpful with what I am trying to do. However, my Drop Down list is a part of another table (table 2) and if I use the existing code, only the first drop down (row 1) gets the pre-populated choices from previous table. Once I add another row to my table 2, my drop down is blank. Is there a change that I can make to this code to make sure all choices get added to every drop down for "n" number of rows in table 2?

 

0 0

Replies

replied on March 30, 2021

This worked! Thank you

1 0
replied on March 31, 2021 Show version history

That's great!  I'm glad it worked for you.

Please consider marking the question as answered.

Have a great day!

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

Sign in to reply to this post.