client script display info in textfield

asd22
Tera Contributor

Hello.

 

I want this client script to display "0" in a text box when the user has the role "admin" and has checked the checkbox "choice_1".
The checkbox is in a variable set in my catalog item where this client script is.
Currently my script is not working and i dont know why. any tips?

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	
	var accessLevel = g_form.getValue('user_role');
	var A0 = g_form.getValue('choice_role.choice_1');
	
	if(accessLevel.includes('Admin') && A0 == true) {
		g_form.setValue('pris_vis', "0");

}}

 

 

 

1 REPLY 1

chetanb
Tera Guru

Hello @asd22 

 

Try below script -

 

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

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

    return; }

  try {

    var accessLevel = g_form.getValue('user_role');

    var A0 = g_form.getValue('choice_role').choice_1;

    if (accessLevel.includes('admin') && A0) {

      g_form.setValue('pris_vis', "0");

    } else {

      g_form.setValue('pris_vis', "");

    }

  } catch (error) {

    gs.error('Client script error: ' + error);

  }

}

 

if my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Regards,

CB