The CreatorCon Call for Content is officially open! Get started here.

How to set default value in choice list based on previous selection

nicolemccray
Tera Expert

I'm trying to set the default value in a choice list to 'New Hire' based up on a previous selection in another field, but my script does not work:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var newHire = g_form.getValue('request_for_new_hire');

if(newHire == 'Yes, and the start date is contingent/not yet determined'){
g_form.setValue('employee_type', 'New Hire');
}
}

1 ACCEPTED SOLUTION

nicolemccray
Tera Expert

Finally got it working by updating the field value, and setValue:

 

if(newHire == 'yes_contingent'){
g_form.setValue('employee_type', 'new_hire', 'New Hire');

View solution in original post

4 REPLIES 4

Alikutty A
Tera Sage

Hello,

Are you setting the actual value for the employee type choice label? It is always best practice to keep your values in lower cases and with underscores.

g_form.setValue('employee_type', 'new_hire');

Thanks!

nicolemccray
Tera Expert

'New Hire' is one of the choice options for the 'Employee Type' variable.  The actual value is 'new_hire', and I've tried changing to this but not working.

SanjivMeher
Kilo Patron
Kilo Patron

Check the actual value of request_for_new_hire. Yes, and the start date is contingent/not yet determined could be a display value, but the actual value could be different. Same applies for employee_type.


Please mark this response as correct or helpful if it assisted you with your question.

nicolemccray
Tera Expert

Finally got it working by updating the field value, and setValue:

 

if(newHire == 'yes_contingent'){
g_form.setValue('employee_type', 'new_hire', 'New Hire');