Trip form, how to update a custom field

Trip form, how to update a custom field

We have a very basic trip form, that contains these custom fields:
Hotel Cost
Airline Cost
Total Cost (read only)

When someone enters a value into "Hotel Cost" or "Airline Cost" we simply want to sum them and update the read-only "Total Cost" field. 

How would we accomplish that? 

I wrote a custom function that is able to sum the values, but I can't figure out how to use that custom function to update that read-only field.