I have read this article to calculate fields based on the value of other fields.
https://xlinesoft.com/articles/how_to_use_calculated_fields.htm
This code works fine in Events -> Before record added
$values["kms"] = DBLookup("SELECT km FROM rutas WHERE id_ruta = ".$values["ruta_id"]);
$values["preciototal"] = DBLookup("SELECT precio FROM servicios WHERE id_servicio = ".$values["servicio_id"]) * $values["kms"];
As you can see, it updates a field called kms based on the value of another field in another table (it is of the Lookup wizard type).
What I want is for that value to be seen directly when a new record is being edited or added "on the fly". I think I have to put the code in "Javascript onload event", but I don't know exactly how to do it
Any idea? Thanks