Can I call a custom function in the on user input of a field?

Can I call a custom function in the on user input of a field?

Dear All,

Lets say that I have a dropdown (input.Dropdown) with 2 choices (Text A, Text B).
I also have a single line 'Description'. I would like when I choose Text A then to fill the phrase 'Text A' in the single line.

I know that I can do it in the on user input  like this

  1. if (input.Dropdown = "Text A"}
  2. {
  3.       input.Description = Dropdown;
  4. }
  5. etc.

My question is if I can do it with custom function.
Can I write custom functions and call them in the on user input? I know how to call functions in the on validate and on success but I am not sure if I can use them in the on user input of a field..

If yes, how can I do the above simple example with a custom function?

The reason why I am asking this easy question is a part of a bigger problem which I have. In an on user input of a field in my application I wrote 2500 lines of code, with the 'Save script' I am waiting at least 4 minutes so I would like to break this code in functions.

That's why I am asking you as a first step this simple question.