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

Question

Question

Change Drop Down Field Value Based on Selection of a Different Drop Down Field Selection

asked on September 21, 2017

I'm creating a New Hire Set Up form which includes a drop down field, Employment Type, with 3 choices:  Team Member; Strategic Partner; and Affinity Partner.  There's also a Pay Type drop down field, also with 3 choices:  Commission; Hourly; and Salary.  I'm trying to create a script that will change the Pay Type field to Commission and disable the field (so it can't be changed to Hourly or Salary) if the Employment Type field is not Team Member.

I've added EmploymentType and PayType class to the respective fields and created the script below.  As you can see below, when the Employment Type field is not Team Member, the script is not changing the Pay Type to Commission and it allows any of the Pay Type choices to be selected.

I'm still going through the learning phase of using jscript, so I'm sure there's something I'm still missing.

As always, any help is greatly appreciated!

Employment Type-Not Team Member Selected.png
Script to change Pay Type field to Commission.png
0 0

Answer

SELECTED ANSWER
replied on September 21, 2017

Hey,

You are pretty close. So just a few things:

1)$(this).is(':checked') - this is generally used for evaluating checkboxes, wont do much for dropdown boxes

2)$('.EmploymentType input').click() - this wont work as the selector is looking specifically for an input field. dropdown boxes use the 'select' selector, also .click() isn't the right trigger in this instance. You want to use 'change' as u specifically want it to run when the value gets changed.

Other then those 2 things you are right on the money. Picking up JavaScript takes a bit but its worth it in the end there is a lot of power in writing your own scripts in Laserfiche.

$(document).ready(function() {
  $(document).on('change','.EmploymentType select',function() {
    if($(this).val() == 'Team Member')
    {
     $('.PayType select').prop('disabled', false);
     $('.PayType select').val('Hourly').change();
    }
    else
    {
      $('.PayType select').prop('disabled', true);
     $('.PayType select').val('Commission').change();
    }
  });
  
});

 

Best of luck mate.

2 0

Replies

replied on September 22, 2017

Thanks, Aaron!  I really appreciate the explanation, as well.  It sure helps with the learning curve!

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

Sign in to reply to this post.