Jim Coyne
Kilo Patron
Part of the "Tips 'N Tricks" series.

 

If you are writing an "onChange" Client or Catalog Client Script and need to look at the value of the field/variable the script is reacting to, you do NOT need to use "g_form.getValue('field_or_variable_name')". There's a variable called "newValue" in the function declaration that you should use instead:

 

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

 

It contains the newly inputed/selected value of the field/variable so you do not need to go and get it again.  Don't

waste any time writing code to go get it, it's there for you to use.  Use it.  Please.

 

It saves time (both writing it and when it executes) and the code is easier to read and understand.