Auto populate field from other form

Auto populate field from other form

How do I populate mileage_log_mileage in mileage_log using a value from sites_distance_from_office from sites table IF value off mileage_log_purpose_of_journey (drop down box) in mileage_log table equals "Office <> Site"