AnsweredAssumed Answered

Basic JavaScript Help: Auto-Populate From Another List

Question asked by kelliganp on May 30, 2018
Latest reply on May 31, 2018 by kelliganp

Hi Folks,

I have some JavaScript that works in part but I want to add a little complexity and am not very god with JS code.

 

NWF$(function() {
//  When an employee is selected using llu_Western_Employee, this runs upon change
NWF$('#'+ jsvar_EmployeeLookup_LLU).on('change', function()
{
  setTimeout(function() {
   NWF$('#'+ jsvar_EmpID_TXT).val(NWF$('#'+ jsvar_EmpID_CAL).val());
   NWF$('#'+ jsvar_LastName_TXT).val(NWF$('#'+ jsvar_LastName_CAL).val());
   NWF$('#'+ jsvar_FirstName_TXT).val(NWF$('#'+ jsvar_FirstName_CAL).val());
   NWF$('#'+ jsvar_MI_TXT).val(NWF$('#'+ jsvar_MI_CAL).val());
   NWF$('#'+ jsvar_Section_TXT).val(NWF$('#'+ jsvar_Section_CAL).val());
   NWF$('#'+ jsvar_DateOfHire_DTE).val(NWF$('#'+ jsvar_DateOfHire_CAL).val());
   NWF$('#'+ jsvar_Phone_TXT).val(NWF$('#'+ jsvar_Phone_CAL).val());
   NWF$('#'+ jsvar_Gender_CHO).val(NWF$('#'+ jsvar_Gender_CAL).val());
   NWF$('#'+ jsvar_PassportNumber_TXT).val(NWF$('#'+ jsvar_PassportNumber_CAL).val());
   NWF$('#'+ jsvar_PassportExpiration_DTE).val(NWF$('#'+ jsvar_PassportExpiration_CAL).val());
   NWF$('#'+ jsvar_SupervisorEmail_TXT).val(NWF$('#'+ jsvar_SupervisorEmail_CAL).val());
  },2000);
});
//  When a contract period is selected using llu_ContractPeriod, this runs upon change
NWF$('#'+ jsvar_CPLookup_LLU).on('change', function()
{
  setTimeout(function() {
   NWF$('#'+ jsvar_RRAvailable_TXT).val(NWF$('#'+ jsvar_RRAvailable_CAL).val());
   NWF$('#'+ jsvar_TravelDayAvailable_TXT).val(NWF$('#'+ jsvar_TravelDayAvailable_CAL).val());
   NWF$('#'+ jsvar_PaidAirfareAvailable_TXT).val(NWF$('#'+ jsvar_PaidAirfareAvailable_CAL).val());

   NWF$('#'+ jsvar_SickAvailable_100_TXT).val(NWF$('#'+ jsvar_SickAvailable_100_CAL).val());
   NWF$('#'+ jsvar_SickAvailable_75_TXT).val(NWF$('#'+ jsvar_SickAvailable_75_CAL).val());
   NWF$('#'+ jsvar_SickAvailable_50_TXT).val(NWF$('#'+ jsvar_SickAvailable_50_CAL).val());
   NWF$('#'+ jsvar_SickAvailable_25_TXT).val(NWF$('#'+ jsvar_SickAvailable_25_CAL).val());
   NWF$('#'+ jsvar_SickAvailable_LWOP_TXT).val(NWF$('#'+ jsvar_SickAvailable_LWOP_CAL).val())
  
   NWF$('#'+ jsvar_SickIssued_100_TXT).val(NWF$('#'+ jsvar_SickIssued_100_CAL).val());
   NWF$('#'+ jsvar_SickIssued_75_TXT).val(NWF$('#'+ jsvar_SickIssued_75_CAL).val());
   NWF$('#'+ jsvar_SickIssued_50_TXT).val(NWF$('#'+ jsvar_SickIssued_50_CAL).val());
   NWF$('#'+ jsvar_SickIssued_25_TXT).val(NWF$('#'+ jsvar_SickIssued_25_CAL).val());
   NWF$('#'+ jsvar_SickIssued_LWOP_TXT).val(NWF$('#'+ jsvar_SickIssued_LWOP_CAL).val())
  },2000);
});
});

 

There are basically two parts to this code block. The first half populates employee data when the control with the Client ID JavaScript variable "jsvar_EmployeeLookup_LLU" is changed. The lines with code like "jsvar_EmpID_CAL" are pointing at calculated value controls.

 

The second half of the code should populate available leave and sick time data when the control with the Client ID JavaScript variable "jsvar_CPLookup_LLU" is changed.

 

The problem I am running into is that when the jsvar_EmployeeLookup_LLU is changed, ALL of the calculated value controls populate. the Leave and Sick Time values do not wait for second list lookup control to change.

 

I suspect that this is just a rookie mistake in my code but I hope someone can see a problem.

 

Thanks and Regards,

Patrick

Outcomes