Call function from a form field and pass a value back to another field in the form?

Call function from a form field and pass a value back to another field in the form?

Is it possible to call a function from a Field On User Input and then have that function send data back to the form? Either to the same field or to another field within the form?

I realise i could update a value in an existing record but in this case i want to pass a value to a form which the user is currently filling in.

Form 1
Field 1 => calls Function => Function calculates some value 
Field 2                                        ||
Field 3   <================ Function passes value back to field in the form.
Field 4

All of this happens while the user is completing the form. No data is submitted.

Is this possible and how do i do it?

I'm sick of writing hundreds of lines of the same code for 15 different elements in the form. One change in the code and I need to make 15 changes to 15 fields. A function would make this way easier but i cant figure out how or if i can pass values back to the form i'm editing?