onchange client script based on multiple conditions

daniellethomson
Tera Expert

I have a request to populate a field based on the answer to multiple fields. The script submits without errors but it is showing an error on the catalog item. Below I have included the script and error. Any help on what I'm not seeing would be great. Thank you!

SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == 'registered') {

          return;

    }

    //Type appropriate comment here, and begin script below

   

}function onChange(control, oldValue, newValue, isLoading)

  {

  var title = g_form.getValue('job_title');

  var location = g_form.getValue('location');

  if ('advisor' == 'Yes') {

      g_form.setValue('compliance_group', "Yes");

  }      

  else if (registered == 'Yes'){

      g_form.setValue('compliance_group', "registered");

  }

  else if (registered == "No" && title == "Senior Vice President" || "Managing Director"){

      g_form.setValue('compliance_group',"leadership");

}

  else if (location == "Des Moines, IA") {

      g_form.setValue('compliance_group',"des_moines");

  } else {

      g_form.setValue('compliance_group',"non_registered");

  }

}

ERROR:

onChange script error: ReferenceError: registered is not defined function h_63033715375a22006ca9d5c543990e4b(control, oldValue, newValue, isLoading) { var title = g_form.getValue('job_title'); var location = g_form.getValue('location'); if ('advisor' == 'Yes') { g_form.setValue('compliance_group', "Yes"); } else if (registered == 'Yes'){ g_form.setValue('compliance_group', "registered"); } else if (registered == "No" && title == "Senior Vice President" || "Managing Director"){ g_form.setValue('compliance_group',"leadership"); } else if (location == "Des Moines, IA") { g_form.setValue('compliance_group',"des_moines"); } else { g_form.setValue('compliance_group',"non_registered"); } }

1 ACCEPTED SOLUTION

Since, the same client script is supposed to trigger onchange of 2 or more variables, you should use 'onSubmit' client script as:



function onSubmit() {


  //Type appropriate comment here, and begin script below


  var title = g_form.getValue('job_title');


  var location = g_form.getValue('location');


  if (g_form.getValue('advisor') == 'Yes')


  g_form.setValue('compliance_group', "Advisors");


  else if (g_form.getValue('registered') == 'Yes')


  g_form.setValue('compliance_group', "Registered");


  else if (title == "Senior Vice President" || title == "Managing Director")


  g_form.setValue('compliance_group',"Leadership");


  else if (location == "Des Moines, IA")


  g_form.setValue('compliance_group',"Des Moines, IA");


  else


  g_form.setValue('compliance_group',"Non registered");


}



Screen Shot 2016-10-06 at 8.30.26 PM.pngScreen Shot 2016-10-06 at 8.30.31 PM.png


Let me know, if you face any problem further.


View solution in original post

10 REPLIES 10

This is working wonderfully. Guess I need to head back to some scripting classes. Thank you so much for your help!!!!