OnChange Client Script Not working after Saving the form

Akshay Sood
Tera Contributor

Hi Everyone,

I have written an onChange Client script which is used to add choices to a "Sub category" drop down list as per selection of category and a new choice field.

It works fine.

However after saving the form when I go back to the "Sub category" field it shows all the choices and does not consider based on category and new choice field.

 

Here is the onChange client script:

 

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

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

 

      return;

   }

 

   var type = g_form.getValue('u_choice_1');

   alert("Category is: "+newValue +" type is: "+type);

   if(newValue=="cat1" && type=="1")

   {

    g_form.clearOptions("u_sub_category");

    g_form.addOption("u_sub_category","0","Other");

    g_form.addOption("u_sub_category","1","Test1");

    g_form.addOption("u_sub_category","2","Test2");

   }

   else if(newValue=="cat2"&& type=="1")

   {

    g_form.clearOptions("u_sub_category");

    g_form.addOption("u_sub_category","3","Test3");

    g_form.addOption("u_sub_category","4","Test4");

   }else{

    g_form.clearOptions("u_sub_category");

    g_form.addOption("u_sub_category","","-- None --");

    g_form.addOption("u_sub_category","0","Other");

    g_form.addOption("u_sub_category","1","Test1");

    g_form.addOption("u_sub_category","2","Test2");

    g_form.addOption("u_sub_category","3","Test3");

    g_form.addOption("u_sub_category","4","Test4");

   }

   

   

}

 

1 REPLY 1

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

After saving the form it is reloaded, and this client scripts doesn't run onload, that is why it is not executing.

You need a script that runs onchange as well as onload.

You can either remove the isloading check form this script then it will work. But it wil be highlighted in healthscans as going against best practice.

Or You can create another Onload script that does the same thing.

-Anurag