My friend Peter from Down Under sent me a great tip the other day about an issue he had with an onChange catalog client script. It’s something that I wasn’t aware of which goes to show you that there’s always something new that you can learn :). Hopefully this tip keeps someone from having to bang their head against a wall for a few hours.
I’m always open to suggestions on how to improve the site and its content. If you have any ideas, questions, or suggestions for the site just use the ‘Ask The Guru‘ link to submit them. Thanks Peter!

Would you be interested in adding this to your site?

function onChange(control,oldValue,newValue,isLoading){
   if(!isLoading) {
      var newValueString = String(newValue);
      switch(newValueString ) {
         case 'Option One':
         g_form.setDisplay('existing_widget',true);
         g_form.setDisplay('existing_thingy',true);
         break;
         case 'Option Two':
         g_form.setDisplay('existing_widget',false);
         g_form.setDisplay('existing_thingy',false);
         break;
         default:
         g_form.setDisplay('existing_widget',false);
         g_form.setDisplay('existing_thingy',false);
         break;
      }
   }
}

It’s a catalogue client script that shows/hides form inputs based on the
option that is chosen. The tricky thing, and the thing that stumped us for
quite a while, is that the system variables provided by the OnChange
function are objects and not strings. So the String(newValue) is critical
or the case statement will fail.

To summarize: OnChange Catalog Client Scripts work differently than regular OnChange client scripts. In order to use the ‘newValue’ and ‘oldValue’ parameters for comparison purposes they need to be converted into a different variable type. The easiest way to do this is to use ‘String(newValue)’ or ‘newValue.toString()’.