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

Question

Question

Auto Populate a single line field from a drop down menu

asked on March 22, 2024 Show version history

I'm looking to auto populate a single line field from a dropdown menu.  Im not sure if i'm missing something here.

I want the user to select a code and the system should auto populate the general ledger.  

I tried a few javascript but it doesnt seem to populate the general ledger

$(document).ready(function() { 
  $(document).on('.GLacctno input');
     }

  
  $(".cf-table-block").on("change", "select",function() {
    $('.cf-table-block tbody tr').each(function () { 
      var chg = $(this).find('.code select').val();
      if (chg == "36") {
        $(this).find('.GLacctno input').val('123-456-789').trigger('change');
      } else {''}
      if (chg == "70") {
        $(this).find('.GLacctno input').val('987-654-321').trigger('change');
      } else {''}
       });
 

 

 

0 0

Answer

SELECTED ANSWER
replied on March 22, 2024 Show version history

If you have the ability to do this with a database lookup instead of Javascript, that solves a lot of problems.  But failing that, we can tweak your code.

Unfortunately, there are multiple errors in the code you posted, so I've just re-written it.  Give this one a try: 

$(document).ready(function() { 

  //Run on form load.
  CodeChangesToGL();
  
  //Run when the table is clicked, so it is applied to new rows.
  $('.cf-table-block').click(CodeChangesToGL);
  
  //Function to populate the GL Accounts based on code value changes.
  function CodeChangesToGL() {
    $('.code select').change(function() {
      var code = $(this).val();
      var glAccount = ''; 
      if (code == '36') {
        glAccount = '123-456-789';
      }
      else if (code == '70') {
        glAccount = '987-654-321';
      }
      $(this).closest('tr').find('.GLacctno input').val(glAccount);
    });
  }
  
});

 

P.S. You can use the {...} code button here in LFAnswers to make you code more readable.

0 0

Replies

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

Sign in to reply to this post.