On Change client script:

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

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

        return;

    }

 

    if (newValue == 'others_specify') {

 

        g_form.clearValue('site_url');

        g_form.clearValue('site_owner_admin');

        g_form.clearValue('description');

        g_form.clearValue('permission');

        g_form.clearValue('user_s_requesting_access');

 

 

        g_form.setMandatory('site_url', true);

        g_form.setDisplay('site_url', true);

 

        g_form.setMandatory('others_please_specify_in_detail', false);

        g_form.setDisplay('others_please_specify_in_detail', true);

 

        g_form.setMandatory('site_owner_admin', false);

        g_form.setDisplay('site_owner_admin', true);

 

        g_form.setMandatory('description', true);

        g_form.setDisplay('description', true);

 

        g_form.setMandatory('permission', true);

        g_form.setDisplay('permission', true);

 

        g_form.setMandatory('business_justification', false);

        g_form.setDisplay('business_justification', false);

 

        g_form.setMandatory('user_s_requesting_access', true);

        g_form.setDisplay('user_s_requesting_access', true);

 

        g_form.setMandatory('start_date', false);

        g_form.setDisplay('start_date', false);

 

        g_form.setMandatory('end_date', false);

        g_form.setDisplay('end_date', false);

 

        g_form.setMandatory('access_level', true);

        g_form.setDisplay('access_level', true);

 

        g_form.setMandatory('source_url', false);

        g_form.setDisplay('source_url', false);

 

        g_form.setMandatory('destination_url', false);

        g_form.setDisplay('destination_url', false);

 

        g_form.setMandatory('site_owner_source_site', false);

        g_form.setDisplay('end_datesite_owner_source_site', false);

 

        g_form.setMandatory('site_owner_destination_site', false);

        g_form.setDisplay('site_owner_destination_site', false);

 

        g_form.setMandatory('preferred_date_and_time_of_migration', false);

        g_form.setDisplay('preferred_date_and_time_of_migration', false);

 

    } else if (newValue == 'Read' || newValue == 'Contribute' || newValue == 'Edit' || newValue == 'Full Control' || newValue == 'Site Collection Administration') {

 

        g_form.clearValue('site_url');

        g_form.clearValue('site_owner_admin');

        g_form.clearValue('description');

        g_form.clearValue('permission');

        g_form.clearValue('user_s_requesting_access');

 

 

        g_form.setMandatory('site_url', true);

        g_form.setDisplay('site_url', true);

 

        g_form.setMandatory('others_please_specify_in_detail', false);

        g_form.setDisplay('others_please_specify_in_detail', false);

 

        g_form.setMandatory('site_owner_admin', false);

        g_form.setDisplay('site_owner_admin', true);

 

        g_form.setMandatory('description', true);

        g_form.setDisplay('description', true);

 

        g_form.setMandatory('permission', true);

        g_form.setDisplay('permission', true);

 

        g_form.setMandatory('access_level', true);

        g_form.setDisplay('access_level', true);

 

        g_form.setMandatory('business_justification', false);

        g_form.setDisplay('business_justification', false);

 

        g_form.setMandatory('user_s_requesting_access', true);

        g_form.setDisplay('user_s_requesting_access', true);

 

        g_form.setMandatory('start_date', false);

        g_form.setDisplay('start_date', false);

 

        g_form.setMandatory('end_date', false);

        g_form.setDisplay('end_date', false);

 

        g_form.setMandatory('source_url', false);

        g_form.setDisplay('source_url', false);

 

        g_form.setMandatory('destination_url', false);

        g_form.setDisplay('destination_url', false);

 

        g_form.setMandatory('site_owner_source_site', false);

        g_form.setDisplay('end_datesite_owner_source_site', false);

 

        g_form.setMandatory('site_owner_destination_site', false);

        g_form.setDisplay('site_owner_destination_site', false);

 

        g_form.setMandatory('preferred_date_and_time_of_migration', false);

        g_form.setDisplay('preferred_date_and_time_of_migration', false);

 

    }

}

 

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

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

        return;

    }

 

    if (newValue == 'others_specify') {

 

        g_form.clearValue('site_url');

        g_form.clearValue('site_owner_admin');

        g_form.clearValue('description');

        g_form.clearValue('permission');

        g_form.clearValue('user_s_requesting_access');

 

 

        g_form.setMandatory('site_url', true);

        g_form.setDisplay('site_url', true);

 

        g_form.setMandatory('others_please_specify_in_detail', false);

        g_form.setDisplay('others_please_specify_in_detail', true);

 

        g_form.setMandatory('site_owner_admin', false);

        g_form.setDisplay('site_owner_admin', true);

 

        g_form.setMandatory('description', true);

        g_form.setDisplay('description', true);

 

        g_form.setMandatory('permission', true);

        g_form.setDisplay('permission', true);

 

        g_form.setMandatory('business_justification', false);

        g_form.setDisplay('business_justification', false);

 

        g_form.setMandatory('user_s_requesting_access', true);

        g_form.setDisplay('user_s_requesting_access', true);

 

        g_form.setMandatory('start_date', false);

        g_form.setDisplay('start_date', false);

 

        g_form.setMandatory('end_date', false);

        g_form.setDisplay('end_date', false);

 

        g_form.setMandatory('access_level', true);

        g_form.setDisplay('access_level', true);

 

        g_form.setMandatory('source_url', false);

        g_form.setDisplay('source_url', false);

 

        g_form.setMandatory('destination_url', false);

        g_form.setDisplay('destination_url', false);

 

        g_form.setMandatory('site_owner_source_site', false);

        g_form.setDisplay('end_datesite_owner_source_site', false);

 

        g_form.setMandatory('site_owner_destination_site', false);

        g_form.setDisplay('site_owner_destination_site', false);

 

        g_form.setMandatory('preferred_date_and_time_of_migration', false);

        g_form.setDisplay('preferred_date_and_time_of_migration', false);

 

    } else if (newValue == 'Read' || newValue == 'Contribute' || newValue == 'Edit' || newValue == 'Full Control' || newValue == 'Site Collection Administration') {

 

        g_form.clearValue('site_url');

        g_form.clearValue('site_owner_admin');

        g_form.clearValue('description');

        g_form.clearValue('permission');

        g_form.clearValue('user_s_requesting_access');

 

 

        g_form.setMandatory('site_url', true);

        g_form.setDisplay('site_url', true);

 

        g_form.setMandatory('others_please_specify_in_detail', false);

        g_form.setDisplay('others_please_specify_in_detail', false);

 

        g_form.setMandatory('site_owner_admin', false);

        g_form.setDisplay('site_owner_admin', true);

 

        g_form.setMandatory('description', true);

        g_form.setDisplay('description', true);

 

        g_form.setMandatory('permission', true);

        g_form.setDisplay('permission', true);

 

        g_form.setMandatory('access_level', true);

        g_form.setDisplay('access_level', true);

 

        g_form.setMandatory('business_justification', false);

        g_form.setDisplay('business_justification', false);

 

        g_form.setMandatory('user_s_requesting_access', true);

        g_form.setDisplay('user_s_requesting_access', true);

 

        g_form.setMandatory('start_date', false);

        g_form.setDisplay('start_date', false);

 

        g_form.setMandatory('end_date', false);

        g_form.setDisplay('end_date', false);

 

        g_form.setMandatory('source_url', false);

        g_form.setDisplay('source_url', false);

 

        g_form.setMandatory('destination_url', false);

        g_form.setDisplay('destination_url', false);

 

        g_form.setMandatory('site_owner_source_site', false);

        g_form.setDisplay('end_datesite_owner_source_site', false);

 

        g_form.setMandatory('site_owner_destination_site', false);

        g_form.setDisplay('site_owner_destination_site', false);

 

        g_form.setMandatory('preferred_date_and_time_of_migration', false);

        g_form.setDisplay('preferred_date_and_time_of_migration', false);

 

    }

}

 

...............................................................................Variable Name - access_level................................................................

I am clearing same values again n again, how can I avoid repetition of code?