OnChange script is not working for HTML type variable in the catalog item

Samiksha2
Mega Sage

Hi All,

I have a variable set in which there is a HTML type variable. 

I have to restrict the characters limit to 32,767.


This the script:

alert("OnChange client script ") ;
 var desc= g_form.getValue('description');
      if (desc.length > 32767) {
		alert("You cannot enter more than 32767 characters.");
        return false; 
    }


I just added alert, but onChange script in not working.

Thanks,
Sam

24 REPLIES 24

Robert H
Mega Sage

Hello @Samiksha2 ,

 

The script works fine on my end. I hope you have not removed the onChange function that needs to surround it. Please also note that onChange Client Scripts will only run when you move the focus to the next field.

 

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

    alert("OnChange client script ");
    var desc = g_form.getValue('description');
    if (desc.length > 32767) {
        alert("You cannot enter more than 32767 characters.");
        return false;
    }

}

 

Regards,

Robert

Hi  @Robert H ,

Yes, I am doing the same. 1st alert is also on coming.

Samiksha2_0-1744374435014.png

This is the variable in the variable set

Samiksha2_1-1744374586085.png


Thanks,
Sam

Hello @Samiksha2 ,

 

In your first post the variable name mentioned in the script was "description", but in your more recent screen shots it's "html_description". What's the actual name?

 

No matter, let's do some simple troubleshooting. Please verify that you have the following things present on your Catalog Item, and nothing else that could interfere:

  • your HTML variable, either directly related to the Catalog Item or part of a Variable Set
  • an onChange script where the selected "Variable name" is the above HTML variable, and the Client Script is either part of the above Variable Set or related directly to the Catalog Item
  • the onChange script contains the following:
if (newValue.length > 5) {
  alert('...');
}

 

If this is the case then this will definitely work, you will get the alert after typing more than 5 characters and then leave the input field's focus. If any of the above is not the case then please adjust accordingly.

 

Regards,

Robert

 

Hi @Robert H ,
I tried. nothing worked. so I changes the Onchange to Onsubmit. Now it is working.

Thanks,
Sam